Skip to content

Commit

Permalink
Merge pull request #2 from detroit-labs/uidevice
Browse files Browse the repository at this point in the history
add UIDevice methods
  • Loading branch information
ctrevarthen committed Feb 11, 2015
2 parents f17a947 + 6dcab27 commit f65d0b5
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DLRUIKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DLRUIKit"
s.version = "1.0.0"
s.version = "1.1.0"
s.summary = "A collection of UIKit categories."
s.homepage = "https://github.com/detroit-labs/dlr-uikit-ios"
s.license = 'MIT'
Expand Down
12 changes: 12 additions & 0 deletions DLRUIKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
433A87031A8561C2008CFA82 /* UIButton+DLR.m in Sources */ = {isa = PBXBuildFile; fileRef = 433A87011A8561C2008CFA82 /* UIButton+DLR.m */; };
433A87051A856455008CFA82 /* UIButton+DLRTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 433A87041A856455008CFA82 /* UIButton+DLRTests.m */; };
433A87091A856929008CFA82 /* ParentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 433A87081A856929008CFA82 /* ParentViewController.m */; };
4362BDC01A8ABA5900B3A89E /* UIDevice+DLR.h in Headers */ = {isa = PBXBuildFile; fileRef = 4362BDBE1A8ABA5900B3A89E /* UIDevice+DLR.h */; };
4362BDC11A8ABA5900B3A89E /* UIDevice+DLR.m in Sources */ = {isa = PBXBuildFile; fileRef = 4362BDBF1A8ABA5900B3A89E /* UIDevice+DLR.m */; };
4362BDC31A8AC0C400B3A89E /* UIDevice+DLRTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4362BDC21A8AC0C400B3A89E /* UIDevice+DLRTests.m */; };
439372ED1A851D8B00A552D5 /* DLRUIKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 439372EC1A851D8B00A552D5 /* DLRUIKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
439372F31A851D8B00A552D5 /* DLRUIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 439372E71A851D8B00A552D5 /* DLRUIKit.framework */; };
439373661A8521A800A552D5 /* UIApplication+DLRLocalNotifications.h in Headers */ = {isa = PBXBuildFile; fileRef = 439373581A8521A800A552D5 /* UIApplication+DLRLocalNotifications.h */; };
Expand Down Expand Up @@ -82,6 +85,9 @@
433A87041A856455008CFA82 /* UIButton+DLRTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIButton+DLRTests.m"; sourceTree = "<group>"; };
433A87071A856929008CFA82 /* ParentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParentViewController.h; sourceTree = "<group>"; };
433A87081A856929008CFA82 /* ParentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ParentViewController.m; sourceTree = "<group>"; };
4362BDBE1A8ABA5900B3A89E /* UIDevice+DLR.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+DLR.h"; sourceTree = "<group>"; };
4362BDBF1A8ABA5900B3A89E /* UIDevice+DLR.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+DLR.m"; sourceTree = "<group>"; };
4362BDC21A8AC0C400B3A89E /* UIDevice+DLRTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+DLRTests.m"; sourceTree = "<group>"; };
439372E71A851D8B00A552D5 /* DLRUIKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DLRUIKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
439372EB1A851D8B00A552D5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
439372EC1A851D8B00A552D5 /* DLRUIKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DLRUIKit.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -282,6 +288,8 @@
433A87011A8561C2008CFA82 /* UIButton+DLR.m */,
4393735A1A8521A800A552D5 /* UIColor+DLR.h */,
4393735B1A8521A800A552D5 /* UIColor+DLR.m */,
4362BDBE1A8ABA5900B3A89E /* UIDevice+DLR.h */,
4362BDBF1A8ABA5900B3A89E /* UIDevice+DLR.m */,
4393735C1A8521A800A552D5 /* UIImage+DLR.h */,
4393735D1A8521A800A552D5 /* UIImage+DLR.m */,
4393735E1A8521A800A552D5 /* UIView+DLRLayoutConstraints.h */,
Expand All @@ -303,6 +311,7 @@
439373751A85220F00A552D5 /* UIApplication+DLRLocalNotificationsTests.m */,
433A87041A856455008CFA82 /* UIButton+DLRTests.m */,
439373761A85220F00A552D5 /* UIColor+DLRTests.m */,
4362BDC21A8AC0C400B3A89E /* UIDevice+DLRTests.m */,
439373771A85220F00A552D5 /* UIImage+DLRTests.m */,
439373781A85220F00A552D5 /* UIView+DLRLayoutConstraintsTests.m */,
439373791A85220F00A552D5 /* UIView+DLRRoundedCornersTests.m */,
Expand All @@ -325,6 +334,7 @@
4393736A1A8521A800A552D5 /* UIImage+DLR.h in Headers */,
433A87021A8561C2008CFA82 /* UIButton+DLR.h in Headers */,
439373681A8521A800A552D5 /* UIColor+DLR.h in Headers */,
4362BDC01A8ABA5900B3A89E /* UIDevice+DLR.h in Headers */,
439373661A8521A800A552D5 /* UIApplication+DLRLocalNotifications.h in Headers */,
4393736C1A8521A800A552D5 /* UIView+DLRLayoutConstraints.h in Headers */,
4393736E1A8521A800A552D5 /* UIView+DLRRoundedCorners.h in Headers */,
Expand Down Expand Up @@ -477,6 +487,7 @@
433A87031A8561C2008CFA82 /* UIButton+DLR.m in Sources */,
439373711A8521A800A552D5 /* UIViewController+DLRParentViewController.m in Sources */,
4393736D1A8521A800A552D5 /* UIView+DLRLayoutConstraints.m in Sources */,
4362BDC11A8ABA5900B3A89E /* UIDevice+DLR.m in Sources */,
4393736F1A8521A800A552D5 /* UIView+DLRRoundedCorners.m in Sources */,
4393736B1A8521A800A552D5 /* UIImage+DLR.m in Sources */,
439373731A8521A800A552D5 /* UIWebView+DLRViewport.m in Sources */,
Expand All @@ -492,6 +503,7 @@
433A87051A856455008CFA82 /* UIButton+DLRTests.m in Sources */,
4393737E1A85220F00A552D5 /* UIImage+DLRTests.m in Sources */,
4393737F1A85220F00A552D5 /* UIView+DLRLayoutConstraintsTests.m in Sources */,
4362BDC31A8AC0C400B3A89E /* UIDevice+DLRTests.m in Sources */,
4393737D1A85220F00A552D5 /* UIColor+DLRTests.m in Sources */,
4393737C1A85220F00A552D5 /* UIApplication+DLRLocalNotificationsTests.m in Sources */,
439373821A85220F00A552D5 /* UIWebView+DLRViewportTests.m in Sources */,
Expand Down
35 changes: 35 additions & 0 deletions DLRUIKit/source/UIDevice+DLR.h
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
69 changes: 69 additions & 0 deletions DLRUIKit/source/UIDevice+DLR.m
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
137 changes: 137 additions & 0 deletions DLRUIKitTests/source/UIDevice+DLRTests.m
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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,30 @@ UIViewController *childViewController = [self.storyboard instantiateViewControll
```objc
[self.containerView dlr_applyRoundedCornersWithRadius:18.0f];
```
---
### UIDevice Category Examples

##### User Interface Idiom

```objc
/** Returns true if current device has an idiom of pad. */
+ (BOOL)dlr_isUserInterfaceIdiomPad;
```

##### System Version
```objc
/** 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;
```

0 comments on commit f65d0b5

Please sign in to comment.