Skip to content

Instantly share code, notes, and snippets.

@Gi-lo
Last active December 22, 2015 21:49
Show Gist options
  • Save Gi-lo/6536397 to your computer and use it in GitHub Desktop.
Save Gi-lo/6536397 to your computer and use it in GitHub Desktop.
Implicit Cast to Bool
// 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