0

I get few warnings in this Xcode 5.1 beta 5 when i installed this new Xcode.

Values of type NSInteger should not be used as format arguments; add an explicit cast to long instead

NSString *time;

NSInteger hour;

time =  [@"" stringByAppendingString:[NSString stringWithFormat:@"%d",hour]];

and tells me to replace it with @"%02ld" or @"%ld"

             
time =  [time stringByAppendingString:[NSString stringWithFormat:@"%02ld",(long)minute]];

It was working fine when i was using Xcode 5.0.2.

so can we release app through Xcode 5.1 beta 5 to IOS 7.1 beta,7.1,6.1 to test on device & to App store?

Should i use Xcode 5.0.2 & use final(non beta) & wait for final version of Xcode 5.1.

P.S. I want to test my apps on device first time & will publish app on store first time..

Vlad Z.
  • 3,401
  • 3
  • 32
  • 60
Jaymin Raval
  • 205
  • 2
  • 19
  • For the warning, see [Why does an NSInteger variable have to typecasted to type long?](http://stackoverflow.com/questions/16075559/why-does-an-nsinteger-variable-have-to-typecasted-to-type-long) - Xcode 5.0.2 gives you the same warning if you compile for 64-bit. – Martin R Feb 25 '14 at 21:55

2 Answers2

1

You can't submit to the app store with a beta version of Xcode. You will have to build your release binary with Xcode 5.0.2.

That said, you should fix those warnings. Just because Xcode 5.0 didn't warn you about them doesn't mean they were ever right.

Kevin
  • 53,822
  • 15
  • 101
  • 132
  • So for int/NSInteger to use as NSString I need to cast all int/NSIntegers to @"%ld"(long double) right? – Jaymin Raval Feb 25 '14 at 22:05
  • @JayminRaval: Only NSInteger/NSUInteger, because that is 32 or 64-bit, depending on the architecture (see link in above comment). You don't have to cast `int`. – Martin R Feb 25 '14 at 22:07
  • ok @MartinR I saw in guide that Xcode supports 32bit & 64bit version so where can I check that my project is 32bit or 64bit? should I build for 64bit or 32bit, which is better? long double casting is necessary in 64bit & %d,%i works on 32 bit as per above link. – Jaymin Raval Feb 25 '14 at 22:10
  • @JayminRaval If your app builds for armv7s it's 64-bit. – Kevin Feb 25 '14 at 22:14
  • @JayminRaval: You can include or exclude 64-bit in the "Architectures" of the "Build Settings". - 64-bit code can performance advantages, see the "64-bit Transition Guide" for more information. – Martin R Feb 25 '14 at 22:16
  • @MartinR I am searching for 32bit 64bit supported devices, so I can build applications according to it. if I build 32bit app it will work on all iPhone devices? 64bit app will work on 64bit supported devices only right? I mean if I build for 32bit app then It will work on iPhone 4,4s,5,5c,5s with ios 6-7? – Jaymin Raval Feb 25 '14 at 22:33
0

There is a difference in this case when compiling for 64-bit vs. 32-bit.

In 64-bit NSInteger is a 64-bit value: typedef long NSInteger In 32-bit NSInteger is a 32-bit value: typedef int NSInteger

So when compiling for 32-bit the %02d is fine. When compiling for 64-bit the compiler wants a %02ld for the wider value. The way to fix this is to use %02ld and cast the value to a long as shown in your second code block. If using NSUInteger cast to unsigned long.

You can read more about this in these iOS articles from Apple:

String Format Specifiers

64-bit Transition Guide

Brian Walker
  • 8,658
  • 2
  • 33
  • 35