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)isEqual:(id)object; | |
{ | |
if ( object == self ) { | |
return YES; | |
} | |
if ( object == nil || ![object isKindOfClass:[self class]] ) { | |
return NO; | |
} | |
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
protocol KeyValueStorable { | |
subscript (key: String) -> AnyObject? { get set } | |
mutating func removeAll() -> Void | |
} | |
extension NSUserDefaults: KeyValueStorable { | |
subscript (key: String) -> AnyObject? { | |
get { return self.objectForKey(key) } | |
set { self.setObject(newValue, forKey: key) } |
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
protocol DictionaryConvertable { | |
static func fromDictionary(dictionary: [String: Any]) throws -> Self | |
func toDictionary() -> [String: Any] | |
} | |
extension DictionaryConvertable { | |
func toDictionary() -> [String: Any] { | |
let mirror = Mirror(reflecting: self) | |
return mirror.children.reduce([:]) { result, child in | |
guard let key = child.label else { return result } |
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
enum UnitType: String { | |
case milligrams = "mg" | |
case grams = "g" | |
case kilograms = "kg" | |
case count = "count" | |
case pounds = "lb" | |
case ounces = "oz" | |
case milliliters = "ml" | |
case liters = "L" | |
case cups = "cup" |