Created
April 20, 2014 09:50
-
-
Save YusukeHosonuma/11110027 to your computer and use it in GitHub Desktop.
Objective-Cでカテゴリ拡張およびUtilクラスによる空文字列チェック ref: http://qiita.com/YusukeHosonuma/items/999d47a269435d094210
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
if ([someString length]) |
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
#import "NSString+Additions.h" | |
@implementation NSString (Additions) | |
- (BOOL)isNotEmpty { | |
return [self length] > 0; | |
} | |
@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
#import "StringUtils.h" | |
@implementation StringUtils | |
+ (BOOL)isEmpty:(NSString*)string { | |
return string == nil || [string length] == 0; | |
} | |
+ (BOOL)isNotEmpty:(NSString*)string { | |
return ![StringUtils isEmpty:string]; | |
} | |
@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
- (void)test_StringUtils_isEmpty | |
{ | |
XCTAssertFalse([StringUtils isEmpty:@"foo"]); | |
XCTAssertTrue ([StringUtils isEmpty:@""]); | |
XCTAssertTrue ([StringUtils isEmpty:nil]); | |
} | |
- (void)test_StringUtils_isNotEmpty | |
{ | |
XCTAssertTrue ([StringUtils isNotEmpty:@"foo"]); | |
XCTAssertFalse([StringUtils isNotEmpty:@""]); | |
XCTAssertFalse([StringUtils isNotEmpty:nil]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment