-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from detroit-labs/uidevice
add UIDevice methods
- Loading branch information
Showing
6 changed files
with
281 additions
and
1 deletion.
There are no files selected for viewing
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
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
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,35 @@ | ||
// | ||
// UIDevice+DLR.h | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 2/10/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIDevice (DLR) | ||
|
||
// User Interface Idiom | ||
|
||
/** Returns true if current device has an idiom of pad. */ | ||
+ (BOOL)dlr_isUserInterfaceIdiomPad; | ||
|
||
// System Version | ||
|
||
/** Returns true if the curent device system version is equal to version. */ | ||
+ (BOOL)dlr_isSystemVersionEqualToVersion:(NSString *)version; | ||
|
||
/** Returns true if the curent device system version is greater than version. */ | ||
+ (BOOL)dlr_isSystemVersionGreaterThanVersion:(NSString *)version; | ||
|
||
/** Returns true if the curent device system version is greater than or equal to version. */ | ||
+ (BOOL)dlr_isSystemVersionGreaterThanOrEqualToVersion:(NSString *)version; | ||
|
||
/** Returns true if the curent device system version is less than version. */ | ||
+ (BOOL)dlr_isSystemVersionLessThanVersion:(NSString *)version; | ||
|
||
/** Returns true if the curent device system version is less than or equal to version. */ | ||
+ (BOOL)dlr_isSystemVersionLessThanOrEqualToVersion:(NSString *)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,69 @@ | ||
// | ||
// UIDevice+DLR.m | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 2/10/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import "UIDevice+DLR.h" | ||
|
||
@implementation UIDevice (DLR) | ||
|
||
#pragma mark - User Interface Idiom | ||
|
||
+ (BOOL)dlr_isUserInterfaceIdiomPad { | ||
BOOL isUserInterfaceIdiomPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad; | ||
return isUserInterfaceIdiomPad; | ||
} | ||
|
||
#pragma mark - System Version | ||
|
||
+ (BOOL)dlr_isSystemVersionEqualToVersion:(NSString *)version { | ||
NSString *systemVersion = [self currentDevice].systemVersion; | ||
return [self dlr_isSystemVersion:systemVersion equalToVersion:version]; | ||
} | ||
|
||
+ (BOOL)dlr_isSystemVersionGreaterThanVersion:(NSString *)version { | ||
NSString *systemVersion = [self currentDevice].systemVersion; | ||
return [self dlr_isSystemVersion:systemVersion greaterThanVersion:version]; | ||
} | ||
|
||
+ (BOOL)dlr_isSystemVersionGreaterThanOrEqualToVersion:(NSString *)version { | ||
NSString *systemVersion = [self currentDevice].systemVersion; | ||
return [self dlr_isSystemVersion:systemVersion greaterThanOrEqualToVersion:version]; | ||
} | ||
|
||
+ (BOOL)dlr_isSystemVersionLessThanVersion:(NSString *)version { | ||
NSString *systemVersion = [self currentDevice].systemVersion; | ||
return [self dlr_isSystemVersion:systemVersion lessThanVersion:version]; | ||
} | ||
|
||
+ (BOOL)dlr_isSystemVersionLessThanOrEqualToVersion:(NSString *)version { | ||
NSString *systemVersion = [self currentDevice].systemVersion; | ||
return [self dlr_isSystemVersion:systemVersion lessThanOrEqualToVersion:version]; | ||
} | ||
|
||
#pragma mark - | ||
|
||
+ (BOOL)dlr_isSystemVersion:(NSString *)systemVersion equalToVersion:(NSString *)version { | ||
return [systemVersion compare:version options:NSNumericSearch] == NSOrderedSame; | ||
} | ||
|
||
+ (BOOL)dlr_isSystemVersion:(NSString *)systemVersion greaterThanVersion:(NSString *)version { | ||
return [systemVersion compare:version options:NSNumericSearch] == NSOrderedDescending; | ||
} | ||
|
||
+ (BOOL)dlr_isSystemVersion:(NSString *)systemVersion greaterThanOrEqualToVersion:(NSString *)version { | ||
return [systemVersion compare:version options:NSNumericSearch] != NSOrderedAscending; | ||
} | ||
|
||
+ (BOOL)dlr_isSystemVersion:(NSString *)systemVersion lessThanVersion:(NSString *)version { | ||
return [systemVersion compare:version options:NSNumericSearch] == NSOrderedAscending; | ||
} | ||
|
||
+ (BOOL)dlr_isSystemVersion:(NSString *)systemVersion lessThanOrEqualToVersion:(NSString *)version { | ||
return [systemVersion compare:version options:NSNumericSearch] != NSOrderedDescending; | ||
} | ||
|
||
@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,137 @@ | ||
// | ||
// UIDevice+DLRTests.m | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 2/10/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "UIDevice+DLR.h" | ||
|
||
@interface UIDevice (DLRPrivate) | ||
|
||
+ (BOOL)dlr_isSystemVersion:(NSString *)systemVersion equalToVersion:(NSString *)version; | ||
+ (BOOL)dlr_isSystemVersion:(NSString *)systemVersion greaterThanVersion:(NSString *)version; | ||
+ (BOOL)dlr_isSystemVersion:(NSString *)systemVersion greaterThanOrEqualToVersion:(NSString *)version; | ||
+ (BOOL)dlr_isSystemVersion:(NSString *)systemVersion lessThanVersion:(NSString *)version; | ||
+ (BOOL)dlr_isSystemVersion:(NSString *)systemVersion lessThanOrEqualToVersion:(NSString *)version; | ||
|
||
@end | ||
|
||
@interface UIDevice_DLRTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation UIDevice_DLRTests | ||
|
||
#pragma mark - User Interface Idiom | ||
|
||
#pragma mark + (BOOL)dlr_isUserInterfaceIdiomPad | ||
|
||
- (void)testIsUserInterfaceIdiomPad { | ||
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { | ||
XCTAssertTrue([UIDevice dlr_isUserInterfaceIdiomPad]); | ||
} | ||
else { | ||
XCTAssertFalse([UIDevice dlr_isUserInterfaceIdiomPad]); | ||
} | ||
} | ||
|
||
#pragma mark - System Version | ||
|
||
#pragma mark + (BOOL)dlr_isSystemVersionEqualToVersion: | ||
|
||
- (void)testIsSystemVersionEqualToVersion { | ||
NSString *systemVersion = [UIDevice currentDevice].systemVersion; | ||
XCTAssertTrue([UIDevice dlr_isSystemVersionEqualToVersion:systemVersion]); | ||
} | ||
|
||
#pragma mark + (BOOL)dlr_isSystemVersion:equalToVersion: | ||
|
||
- (void)testIsSystemVersion_equalToVersion { | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"8.1" equalToVersion:@"8.1"]); | ||
|
||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"8" equalToVersion:@"8.0"]); | ||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"8" equalToVersion:@"8.1"]); | ||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"8.0" equalToVersion:@"8.1"]); | ||
} | ||
|
||
#pragma mark + (BOOL)dlr_isSystemVersionGreaterThanVersion: | ||
|
||
- (void)testIsSystemVersionGreaterThanVersion { | ||
XCTAssertTrue([UIDevice dlr_isSystemVersionGreaterThanVersion:@"6.1.1"]); | ||
} | ||
|
||
#pragma mark + (BOOL)dlr_isSystemVersion:greaterThanVersion: | ||
|
||
- (void)testIsSystemVersion_greaterThanVersion { | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"8.1.1" greaterThanVersion:@"7"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"8" greaterThanVersion:@"7"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7.1" greaterThanVersion:@"7"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7.1.1" greaterThanVersion:@"7.1"]); | ||
|
||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"7" greaterThanVersion:@"7"]); | ||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"7" greaterThanVersion:@"8"]); | ||
} | ||
|
||
#pragma mark + (BOOL)dlr_isSystemVersionGreaterThanOrEqualToVersion: | ||
|
||
- (void)testIsSystemVersionGreaterThanOrEqualToVersion { | ||
NSString *systemVersion = [UIDevice currentDevice].systemVersion; | ||
XCTAssertTrue([UIDevice dlr_isSystemVersionGreaterThanOrEqualToVersion:systemVersion]); | ||
} | ||
|
||
#pragma mark + (BOOL)dlr_isSystemVersion:greaterThanOrEqualToVersion: | ||
|
||
- (void)testIsSystemVersion_greaterThanOrEqualToVersion { | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"8.1.1" greaterThanOrEqualToVersion:@"7"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"8" greaterThanOrEqualToVersion:@"7"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7.1" greaterThanOrEqualToVersion:@"7"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7.1.1" greaterThanOrEqualToVersion:@"7.1"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7" greaterThanOrEqualToVersion:@"7"]); | ||
|
||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"7.1.1" greaterThanOrEqualToVersion:@"7.1.2"]); | ||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"7" greaterThanOrEqualToVersion:@"8"]); | ||
} | ||
|
||
#pragma mark + (BOOL)dlr_isSystemVersionLessThanVersion: | ||
|
||
- (void)testIsSystemVersionLessThanVersion { | ||
XCTAssertTrue([UIDevice dlr_isSystemVersionLessThanVersion:@"14.9"]); | ||
} | ||
|
||
#pragma mark + (BOOL)dlr_isSystemVersion:lessThanVersion: | ||
|
||
- (void)testIsSystemVersion_lessThanVersion { | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7" lessThanVersion:@"8.1.1"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7" lessThanVersion:@"8"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7" lessThanVersion:@"7.1"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7.1" lessThanVersion:@"7.1.1"]); | ||
|
||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"7" lessThanVersion:@"7"]); | ||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"8" lessThanVersion:@"7"]); | ||
} | ||
|
||
#pragma mark + (BOOL)dlr_isSystemVersionLessThanOrEqualToVersion: | ||
|
||
- (void)testIsSystemVersionLessThanOrEqualToVersion { | ||
NSString *systemVersion = [UIDevice currentDevice].systemVersion; | ||
XCTAssertTrue([UIDevice dlr_isSystemVersionLessThanOrEqualToVersion:systemVersion]); | ||
} | ||
|
||
#pragma mark + (BOOL)dlr_isSystemVersion:lessThanOrEqualToVersion: | ||
|
||
- (void)testIsSystemVersion_lessThanOrEqualToVersion { | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7" lessThanOrEqualToVersion:@"8.1.1"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7" lessThanOrEqualToVersion:@"8"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7" lessThanOrEqualToVersion:@"7.1"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7.1" lessThanOrEqualToVersion:@"7.1.1"]); | ||
XCTAssertTrue([UIDevice dlr_isSystemVersion:@"7" lessThanOrEqualToVersion:@"7"]); | ||
|
||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"7.1.2" lessThanOrEqualToVersion:@"7.1.1"]); | ||
XCTAssertFalse([UIDevice dlr_isSystemVersion:@"8" lessThanOrEqualToVersion:@"7"]); | ||
} | ||
|
||
@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