문제

I am getting my app's version like this:

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

And then trying to convert it to a float like this:

[version floatValue]

Now that all works great, but when I have a minor version like "1.1.1" everything behind the second decimal point is truncated.

What is the best way to keep everything behind the second decimal point?

도움이 되었습니까?

해결책

To keep it in sync with how you started...

int major, minor, bug;
NSArray *versionItems = [version componentsSeparatedByString:@"."];
major = [[versionItems objectAtIndex:0] intValue]; 
minor = [[versionItems objectAtIndex:1] intValue];
bug = [[versionItems objectAtIndex:2] intValue];

But I'd recommend looking at this..

How do I determine the OS version at runtime in OS X or iOS (without using Gestalt)?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top