Skip to content

Instantly share code, notes, and snippets.

@igor-makarov
Created October 14, 2020 11:02
Show Gist options
  • Save igor-makarov/3f25ac51e39360060335290ccbd3acc5 to your computer and use it in GitHub Desktop.
Save igor-makarov/3f25ac51e39360060335290ccbd3acc5 to your computer and use it in GitHub Desktop.
// Returns true iff the string is non-nil and contains at least one non-whitespace character
CG_INLINE BOOL MVNonEmptyString(NSString * _Nullable string) {
if([string isKindOfClass:NSAttributedString.class]) {
string = ((NSAttributedString*)string).string;
}
NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSUInteger len = string.length;
for (NSUInteger i = 0; i < len; i++) {
unichar c = [string characterAtIndex:i];
if (![whitespace characterIsMember:c]) {
return YES;
}
}
return NO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment