Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Rails' nil?, for Objective-C
#import <Foundation/Foundation.h>
@interface NSObject (NSNullCheck)
- (BOOL)isNull;
@implementation NSObject (NSNullCheck)
- (BOOL)isNull { return NO; }
@implementation NSNull (NSNullCheck)
- (BOOL)isNull { return YES; }
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
Something went wrong with that request. Please try again.