Created
April 13, 2014 04:38
-
-
Save YusukeHosonuma/10569437 to your computer and use it in GitHub Desktop.
Objective-Cで空文字列のチェック ref: http://qiita.com/YusukeHosonuma/items/3103ca5353fd585b08bd
This file contains hidden or 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
#define IS_EMPTY(s) ((s == nil) || ([s length] == 0)) | |
NSString *emptyString = @""; | |
NSString *nilString = nil; | |
NSString *someString = @"foo"; | |
// nilまたは空文字列でないかチェックする | |
NSLog(@"%@", !IS_EMPTY(emptyString) ? @"YES" : @"NO"); | |
NSLog(@"%@", !IS_EMPTY(nilString) ? @"YES" : @"NO"); | |
NSLog(@"%@", !IS_EMPTY(someString) ? @"YES" : @"NO"); |
This file contains hidden or 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
// nilまたは空文字列でないかチェックする | |
NSLog(@"%@", [emptyString length] ? @"YES" : @"NO"); | |
NSLog(@"%@", [nilString length] ? @"YES" : @"NO"); | |
NSLog(@"%@", [someString length] ? @"YES" : @"NO"); |
This file contains hidden or 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
// 明示的なnilおよび長さチェック | |
if (someString != nil && [someString length] > 0) | |
// 言語仕様を活かしたチェック | |
if ([someString length]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment