A port of Apache Maven's VersionComparator class to Objective-C. This library will support comparing any string whose value conforms to the standard Maven 2.x version numbering scheme.
#import "NSString+GSVersionComparator.h"
// Compare iOS versions
if ([[UIDevice currentDevice].systemVersion gs_versionLessThan:@"7.0"]) {
// Do something specific for iOS 6 and below
}
// Compare arbitrary version strings
NSURL *apiEndpoint = [NSURL URLWithString:@"http://example.com/2.0/resource"];
NSString *versionComponent = apiEndpoint.pathComponents[1];
NSString *supportedAPIVersion = @"2";
if ([versionComponent gs_versionEquals:supportedAPIVersion]) {
// Your client supports this api version, it's safe to proceed
}
// Compare complex version strings like '1' and '1.0-0'
BOOL test = [@"1" gs_versionEquals:@"1.0-0"]; // Returns YES
BOOL test = [@"1.0.b" gs_versionGreaterThan:@"1.0.a"]; // Returns YES
BOOL test = [@"1.0" gs_versionLessThan:@"1.0-SNAPSHOT"]; // Returns NO
Check the unit tests for more examples of version strings supported.
GSVersionComparator is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "GSVersionComparator"
Ryan Brignoni
Twitter: @RyanBrignoni
GSVersionComparator is available under the Apache v2 license. See the LICENSE file for more info.
=======