mike_haney
mike_haney

Reputation: 545

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.

Upvotes: 1

Views: 423

Answers (2)

DougW
DougW

Reputation: 30025

self.rect must not be a valid CGRect. Are you sure you don't mean self.frame?

Upvotes: 1

progrmr
progrmr

Reputation: 77191

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, 

Upvotes: 1

Related Questions