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 trial

iOS

Jacob Cho
Jacob Cho
7,937 Points

Spritekit: NSInteger score vs NSInteger *score

I had a bug in my Spacecat game and the score was going up by multiples of 400 instead of 100 as it was supposed to be even though the PointsPerHit was set to 100. It was because I defined the property as NSInteger *score instead of NSInteger score.

Could anyone tell me why it would multiply the points by 4?

1 Answer

Because when you use the ( * ) you are saying you want a pointer to an NSInteger not an NSInteger.

When you do something like

NSInteger myInt; myInt ++; // Complier reads this as myInt = myInt + 1;

But when you do NSInteger *myInt; myInt++; // Complier reads this as myInt = myInt + 4; This is because an NSInteger takes four bytes in memory up and pointers are memory locations.