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
Benjamin Jones
2,269 PointsSpace Cats App problem - "Values of type "NSinteger should not be used as format arguments..
Hi there I am following the tutorial for building my first sprite game app, and i have got on fine so far, but now receiving errors, with my code..
In two separate instances, i am using:
SKLabelNode scoreLabel = (SKLabelNode)[self childNodeWithName:@"Score"]; scoreLabel.text = [NSString stringWithFormat:@"%d",self.score];
and
- (bool) loseLife { if (self.lives > 0) { NSString *lifeNodeName = [NSString stringWithFormat:@"Life%d",self.lives];
in both instances i get the amber exclamation mark " Values of type 'NSinteger' should not be used as format arguments; add an explicit cast to 'long' instead - and recommends I use %LD.. this isn't in the tutorial, and wondering whether i am doing anything wrong..
OS X 10.9.4 - XCODE version 5.1.1
many thanks guys..
Ben
1 Answer
Stone Preston
42,016 Pointsuse %ld as the format specifier and cast the value to a long.
scoreLabel.text = [NSString stringWithFormat:@"%ld", (long) self.score];
according to this stack overflow post:
You get this warning if you compile on OS X (64-bit), because on that platform NSInteger is defined as long and is a 64-bit integer. The %d format, on the other hand, is for int, which is 32-bit. So the format and the actual parameter do not match in size.
Since NSInteger is 32-bit or 64-bit, depending on the platform, the compiler recommends to add a cast to long generally.