Objective-C stringWithFormat misses an argument?
When I run this code:
- (NSString *)description{
return [NSString stringWithFormat:@"(FROG idle:%i animating:%i rect:%@ position:%@ tongue:%@)",
self.idleTime,
self.animating,
开发者_如何转开发 NSStringFromCGRect(self.rect),
NSStringFromCGPoint(self.position),
tongue
];
}
I get the following output:
(FROG idle:0 animating:0 rect:(null) position:{{1,2}{3,4}} tongue:{5,6})
This is wrong because it seems to be skipping the rect format string and placing everything displaced by one. So idle and animating are what I expect, then rect is skipped, but the result from NSStringFromCGRect(self.rect) is placed into position, then the result for position is pushed to tongue, then tongue is not displayed at all.
I'm at a loss.
I can't tell without the declarations for idleTime and animating, but one or both of this is probably the wrong type for the %i specifier. Perhaps idleTime is a double (NSTimeInterval)?
Depending on what their actual types are, you could convert them to int:
(int)self.idleTime,
(int)self.animating,
self.rect must not be a valid CGRect. Are you sure you don't mean self.frame?
精彩评论