Created
June 10, 2016 21:24
-
-
Save FreeMasen/c9afc712c680891663cc667e13922c96 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UnderlyingValue { | |
case string(Stirng) | |
case int(Int) | |
case double(Double) | |
case array([[String:AnyObject]]) | |
case dictionary([String:AnyObject]]) | |
var dictionary: [String:AnyObject] { | |
return determinSelf<>([String: AnyObject]) | |
} | |
func determinSelf<T>() -> T? { | |
switch self { | |
case .string(let value): | |
if value.type == T { | |
return value | |
} | |
return nil | |
case .int(let value): | |
if value.type == T { | |
return value | |
} | |
return nil | |
case .double(let value): | |
if value.type == T { | |
return value | |
} | |
return nil | |
case .array(let value): | |
if value.type == T { | |
return value | |
} | |
case .dictionary(let value): | |
if value.type == T { | |
return value | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment