Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructed project, added building of static library, added DTVersion…
… class.
- Loading branch information
Showing
16 changed files
with
487 additions
and
85 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Classes | ||
#import "DTVersion.h" | ||
|
||
// Categories | ||
#import "NSString+DTFormatNumbers.h" | ||
#import "NSURL+DTAppLinks.h" | ||
#import "NSURL+DTPrefLinks.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// DTVersion.h | ||
// DTFoundation | ||
// | ||
// Created by Oliver Drobnik on 11/25/11. | ||
// Copyright (c) 2011 Cocoanetics. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/** | ||
Class that represents a version number comprised of major, minor and maintenance number separarated by dots. For example "1.2.2". | ||
This encapsulation simplifies comparing versions against each other. Sub-numbers that are omitted on creating a `DTVersion` are assumed to be 0. | ||
*/ | ||
@interface DTVersion : NSObject | ||
{ | ||
NSUInteger _majorVersion; | ||
NSUInteger _minorVersion; | ||
NSUInteger _maintenanceVersion; | ||
} | ||
|
||
/** | ||
The receiver's major version number. | ||
*/ | ||
@property (nonatomic, readonly) NSUInteger majorVersion; | ||
|
||
/** | ||
The receiver's minor version number. | ||
*/ | ||
@property (nonatomic, readonly) NSUInteger minorVersion; | ||
|
||
/** | ||
The receiver's maintenance version number. | ||
*/ | ||
@property (nonatomic, readonly) NSUInteger maintenanceVersion; | ||
|
||
/**------------------------------------------------------------------------------------- | ||
@name Creating Versions | ||
--------------------------------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
creates and returns a `DTVersion` object initialized using the provided string | ||
@param versionString A string with a version number. | ||
@returns A DTVersion object or `nil` if the string is not a valid version number | ||
@see initWithMajor:minor:maintenance: | ||
*/ | ||
+ (DTVersion *)versionWithString:(NSString *)versionString; | ||
|
||
/** | ||
creates and retuns a `DTVersion` object initialized with the version information of the current application | ||
@returns A DTVersion object or `nil` if the string of the current application is not a valid version number | ||
*/ | ||
+ (DTVersion *)appBundleVersion; | ||
|
||
/** | ||
creates and retuns a `DTVersion` object initialized with the version information of the operating system | ||
@returns A `DTVersion` object or `nil` if the string of the current application is not a valid version number | ||
*/ | ||
+ (DTVersion *)osVersion; | ||
|
||
/** | ||
creates and returns a `DTVersion` object initialized using the provided string | ||
@param major The major version number of the version. | ||
@param minor The minor version number of the version. | ||
@param maintenance The maintenance version number of the version. | ||
@returns A `DTVersion` object or `nil` if the string is not a valid version number | ||
*/ | ||
- (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance; | ||
|
||
/**------------------------------------------------------------------------------------- | ||
@name Comparing Versions | ||
--------------------------------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
Returns a Boolean value that indicates whether a given `DTVersion` is equal to the receiver. | ||
@param version The `DTVersion` instance to compare against. | ||
@returns `YES` if the other object is equal to the receiver | ||
*/ | ||
- (BOOL) isEqualToVersion:(DTVersion *)version; | ||
|
||
/** | ||
Returns a Boolean value that indicates whether a given string is equal to the receiver. | ||
@param versionString The string to compare the receiver against. | ||
@returns `YES` if the other object is equal to the receiver | ||
*/ | ||
- (BOOL) isEqualToString:(NSString *)versionString; | ||
|
||
/** | ||
Returns a Boolean value that indicates whether a given object is equal to the receiver. | ||
If the other object is an `NSString` then isEqualToString: is called. If it is a `DTVersion` instance isEqualToVersion: is called. | ||
@param object An NSString or `DTVersion` to compare against. | ||
@returns `YES` if the other object is equal to the receiver | ||
*/ | ||
- (BOOL) isEqual:(id)object; | ||
|
||
/** | ||
Compares the receiver to object. | ||
@param version The `DTVersion` instance to compare the receiver with. | ||
@returns `NSOrderedAscending` if the receiver precedes object in version ordering, `NSOrderedSame` if they are equal, and `NSOrderedDescending` if the receiver is higher than object. | ||
*/ | ||
- (NSComparisonResult)compare:(DTVersion *)version; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
// | ||
// DTVersion.m | ||
// DTFoundation | ||
// | ||
// Created by Oliver Drobnik on 11/25/11. | ||
// Copyright (c) 2011 Cocoanetics. All rights reserved. | ||
// | ||
|
||
#import "DTVersion.h" | ||
#import <UIKit/UIKit.h> | ||
|
||
@implementation DTVersion | ||
|
||
- (DTVersion *)initWithMajor:(NSUInteger)majorVersion minor:(NSUInteger)minorVersion maintenance:(NSUInteger)maintenanceVersion | ||
{ | ||
self = [super init]; | ||
if (self) | ||
{ | ||
_majorVersion = majorVersion; | ||
_minorVersion = minorVersion; | ||
_maintenanceVersion = maintenanceVersion; | ||
} | ||
return self; | ||
} | ||
|
||
+ (DTVersion *)versionWithString:(NSString*)versionString | ||
{ | ||
if (!versionString) | ||
{ | ||
return nil; | ||
} | ||
|
||
NSInteger major = 0; | ||
NSInteger minor = 0; | ||
NSInteger maintenance = 0; | ||
|
||
int i=0; | ||
NSScanner *scanner = [NSScanner scannerWithString:versionString]; | ||
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"."]]; | ||
|
||
while (i<3 && ![scanner isAtEnd]) | ||
{ | ||
switch (i) | ||
{ | ||
case 0: | ||
{ | ||
if (![scanner scanInteger:&major]) | ||
{ | ||
return nil; | ||
} | ||
break; | ||
} | ||
|
||
case 1: | ||
{ | ||
if (![scanner scanInteger:&minor]) | ||
{ | ||
return nil; | ||
}; | ||
break; | ||
} | ||
|
||
case 2: | ||
{ | ||
if (![scanner scanInteger:&maintenance]) | ||
{ | ||
return nil; | ||
}; | ||
break; | ||
} | ||
|
||
default: | ||
{ | ||
// ignore suffix | ||
break; | ||
} | ||
} | ||
i++; | ||
} | ||
|
||
if (major >= 0 && | ||
minor >= 0 && | ||
maintenance >= 0) | ||
{ | ||
return [[DTVersion alloc] initWithMajor:major minor:minor maintenance:maintenance]; | ||
} | ||
|
||
return nil; | ||
} | ||
|
||
+ (DTVersion*)appBundleVersion | ||
{ | ||
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; | ||
DTVersion* retVersion = [DTVersion versionWithString:version]; | ||
|
||
return retVersion; | ||
} | ||
|
||
+ (DTVersion *)osVersion | ||
{ | ||
NSString *version = [[UIDevice currentDevice] systemVersion]; | ||
return [DTVersion versionWithString:version]; | ||
} | ||
|
||
- (BOOL) isEqualToVersion:(DTVersion *)version | ||
{ | ||
return (self.majorVersion == version.majorVersion) && (self.minorVersion == version.minorVersion) && (self.maintenanceVersion == version.maintenanceVersion); | ||
} | ||
|
||
- (BOOL) isEqualToString:(NSString *)versionString | ||
{ | ||
DTVersion *versionToTest = [DTVersion versionWithString:versionString]; | ||
return [self isEqualToVersion:versionToTest]; | ||
} | ||
|
||
|
||
- (BOOL) isEqual:(id)object | ||
{ | ||
if ([object isKindOfClass:[DTVersion class]]) | ||
{ | ||
return [self isEqualToVersion:(DTVersion*)object]; | ||
} | ||
if ([object isKindOfClass:[NSString class]]) | ||
{ | ||
return [self isEqualToString:(NSString*)object]; | ||
} | ||
return NO; | ||
} | ||
|
||
- (NSComparisonResult)compare:(DTVersion *)version | ||
{ | ||
if (version == nil) | ||
{ | ||
return NSOrderedDescending; | ||
} | ||
|
||
if (self.majorVersion < version.majorVersion) | ||
{ | ||
return NSOrderedAscending; | ||
} | ||
if (self.majorVersion > version.majorVersion) | ||
{ | ||
return NSOrderedDescending; | ||
} | ||
if (self.minorVersion < version.minorVersion) | ||
{ | ||
return NSOrderedAscending; | ||
} | ||
if (self.minorVersion > version.minorVersion) | ||
{ | ||
return NSOrderedDescending; | ||
} | ||
if (self.maintenanceVersion < version.maintenanceVersion) | ||
{ | ||
return NSOrderedAscending; | ||
} | ||
if (self.maintenanceVersion > version.maintenanceVersion) | ||
{ | ||
return NSOrderedDescending; | ||
} | ||
|
||
return NSOrderedSame; | ||
} | ||
|
||
|
||
- (NSString *)description | ||
{ | ||
return [NSString stringWithFormat:@"%d.%d.%d", _majorVersion, _minorVersion, _maintenanceVersion]; | ||
} | ||
|
||
|
||
|
||
@synthesize majorVersion = _majorVersion; | ||
@synthesize minorVersion = _minorVersion; | ||
@synthesize maintenanceVersion = _maintenanceVersion; | ||
|
||
@end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.