Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Created March 10, 2012 07:22
Show Gist options
  • Save tonyarnold/2010649 to your computer and use it in GitHub Desktop.
Save tonyarnold/2010649 to your computer and use it in GitHub Desktop.
Exhaustively check if an Objective-C object is "empty"
static inline BOOL CBIsEmpty(id obj) {
return obj == nil
|| (NSNull *)obj == [NSNull null]
|| ([obj respondsToSelector:@selector(length)] && [obj length] == 0)
|| ([obj respondsToSelector:@selector(count)] && [obj count] == 0);
}
@orj
Copy link

orj commented Mar 12, 2012

Yeah, true. msgSend will indeed return 0 if the input is nil. And the 0u is just me being ultra pedantic. It is completely unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment