-2

Can someone help me with this Issue/error I'm getting on my iOS app: Values of type 'NSInteger' should not be used as format argument; add an explicit cast to 'long' instead

My code in Viewcontroller.m (issue highlighted on first line):

    NSString *imgName = [NSString stringWithFormat:@"button%iop_on.png",b.tag];
    [b setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
    activeButton = b;
    [self performSelector:@selector(validate)withObject:nil  afterDelay:ti];

Any help would be appreciated. Thanks

SteveFerg
  • 3,466
  • 7
  • 19
  • 31
Ben Nash
  • 1
  • 1
  • possible duplicate of [Why does an NSInteger variable have to be cast to long when used as a format argument?](http://stackoverflow.com/questions/16075559/why-does-an-nsinteger-variable-have-to-be-cast-to-long-when-used-as-a-format-arg) – Guillaume Algis Jul 25 '15 at 16:53

1 Answers1

4

NSInteger can be a different size dependant on the platform you are compiling for.

You should use the format %ld and then cast tag with (long)b.tag

NSString *imgName = [NSString stringWithFormat:@"button%ldop_on.png", (long)b.tag];

See String Programming Guide > String Format Specifiers for reference

Paul.s
  • 38,494
  • 5
  • 70
  • 88