Skip to content

Instantly share code, notes, and snippets.

@FreeMasen
Created June 10, 2016 21:24
Show Gist options
  • Save FreeMasen/c9afc712c680891663cc667e13922c96 to your computer and use it in GitHub Desktop.
Save FreeMasen/c9afc712c680891663cc667e13922c96 to your computer and use it in GitHub Desktop.
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