Skip to content

Instantly share code, notes, and snippets.

@axelrivera
Created August 2, 2013 13:24
Show Gist options
  • Save axelrivera/6139844 to your computer and use it in GitHub Desktop.
Save axelrivera/6139844 to your computer and use it in GitHub Desktop.
Function to test empty objects in Objective-C
static inline BOOL IsEmpty(id thing) {
return thing == nil
|| thing == [NSNull null]
|| ([thing respondsToSelector:@selector(length)]
&& [(NSData *)thing length] == 0)
|| ([thing respondsToSelector:@selector(count)]
&& [(NSArray *)thing count] == 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment