Question

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?

Was it helpful?

Solution

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)?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top