Created
May 6, 2014 15:43
-
-
Save youens/8caba0f1edfcb40ff2ed to your computer and use it in GitHub Desktop.
Flexible Boolean String Parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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