Last active
December 22, 2015 21:49
-
-
Save Gi-lo/6536397 to your computer and use it in GitHub Desktop.
Implicit Cast to Bool
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
// Just a string | |
NSString *string = @"Trololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololololol"; | |
// Not so clever implicit BOOL cast | |
BOOL hasText = [string length]; // Just add "> 0" to fix it btw. | |
// Sure it has some text! ... eh wait what | |
NSLog(@"String has some text: %@", hasText ? @"YES" : @"NO"); | |
// And to have some reference to the blog post ... (http://blog.bignerdranch.com/564-bools-sharp-corners/) | |
if ([string length] == YES) { | |
NSLog(@"String has some text!"); | |
} else { | |
NSLog(@"String is empty!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment