PageRenderTime 25ms CodeModel.GetById 2ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

/libs/ObjectAL/Support/IOSVersion.m

http://github.com/kstenerud/ObjectAL-for-iPhone
Objective C | 53 lines | 36 code | 11 blank | 6 comment | 12 complexity | a8e3f8463b3ef2fb5bf7ed40ab746bad MD5 | raw file
 1//
 2//  IOSVersion.m
 3//  ObjectiveGems
 4//
 5//  Created by Karl Stenerud on 10-11-07.
 6//
 7
 8#import "IOSVersion.h"
 9#import <UIKit/UIKit.h>
10
11
12SYNTHESIZE_SINGLETON_FOR_CLASS_PROTOTYPE(IOSVersion);
13
14
15@implementation IOSVersion
16
17SYNTHESIZE_SINGLETON_FOR_CLASS(IOSVersion);
18
19- (id) init
20{
21	if(nil != (self = [super init]))
22	{
23		NSString* versionStr = [[UIDevice currentDevice] systemVersion];
24		unichar ch = [versionStr characterAtIndex:0];
25		if(ch < '0' || ch > '9' || [versionStr characterAtIndex:1] != '.')
26		{
27			NSLog(@"Error: %s: Cannot parse iOS version string \"%@\"", __PRETTY_FUNCTION__, versionStr);
28		}
29		
30		version = (float)(ch - '0');
31		
32		float multiplier = 0.1f;
33		unsigned int vLength = [versionStr length];
34		for(unsigned int i = 2; i < vLength; i++)
35		{
36			ch = [versionStr characterAtIndex:i];
37			if(ch >= '0' && ch <= '9')
38			{
39				version += (ch - '0') * multiplier;
40				multiplier /= 10;
41			}
42			else if('.' != ch)
43			{
44				break;
45			}
46		}
47	}
48	return self;
49}
50
51@synthesize version;
52
53@end