Skip to content

Instantly share code, notes, and snippets.

@youens
Created May 6, 2014 15:43
Show Gist options
  • Save youens/8caba0f1edfcb40ff2ed to your computer and use it in GitHub Desktop.
Save youens/8caba0f1edfcb40ff2ed to your computer and use it in GitHub Desktop.
Flexible Boolean String Parser
+ (BOOL)parseBooleanValueFromString:(NSString *)value defaultValue:(BOOL)defaultValue {
if (!value) return defaultValue;
if ([@[@"1", @"yes", @"on", @"true"] containsObject:[value lowercaseString]]) {
return YES;
}
else if ([@[@"0", @"no", @"off", @"false"] containsObject:[value lowercaseString]]) {
return NO;
}
return defaultValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment