Created
November 19, 2010 22:40
-
-
Save mdippery/707337 to your computer and use it in GitHub Desktop.
Rails' nil?, for Objective-C
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 <Foundation/Foundation.h> | |
@interface NSObject (NSNullCheck) | |
- (BOOL)isNull; | |
@end | |
@implementation NSObject (NSNullCheck) | |
- (BOOL)isNull { return NO; } | |
@end | |
@implementation NSNull (NSNullCheck) | |
- (BOOL)isNull { return YES; } | |
@end | |
int main(int argc, char **argv) | |
{ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
NSString *s = @"My string"; | |
NSNull *n = [NSNull null]; | |
NSLog(@"s is null? %@ (should be NO)", [s isNull] ? @"YES" : @"NO"); | |
NSLog(@"n is null? %@ (should be YES)", [n isNull] ? @"YES" : @"NO"); | |
[pool release]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment