Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialdixonlo
846 Pointswhy is ball a pointer (*ball)? Is it not possible to just use a variable ball?
ball is declared as *ball. Does this mean it is a pointer? When are pointers used and when are normal variables used?
2 Answers
Andrew Boryk
15,916 PointsPoints are used to send the value of variable to an address in memory. The reason why you must have a point on Ball is because Ball is an Object, and all objects need to have a reference point in memory. Primitive data types don't require pointers, however you may use them. Objective-C is an object oriented language, so even Strings (which in other languages wouldn't be objects), are actually objects and are declared with NSString *string. Hope I helped, been programming in Objective-C for a little over two years. I could be off a bit, but that is what I've always told myself.
Michael Hulet
47,913 PointsIt's been a while since I've done iOS development (I haven't actually taken the Treehouse track, but I've done a very little in the past), but I think all objects in Objective-C are pointed to, and I think it has to do with the fact that they have setter and getter methods that you can modify, and those actually store the variable
dixonlo
846 Pointsi see, thanks michael!
dixonlo
846 Pointsdixonlo
846 Pointsi like it, thats what ill tell myself too.
Michael Bowen
770 PointsMichael Bowen
770 PointsTo add, you need to use pointers for objects because they are initialized in the heap. Primitives are on the stack, which make them local, so you don't need pointers for them.