0

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jonathan
  • 507
  • 5
  • 15

1 Answers1

2

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

Community
  • 1
  • 1
estobbart
  • 1,137
  • 12
  • 28