Last active
January 26, 2017 12:10
-
-
Save elland/47d73d605d2300e55dfdb23211b41ca3 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
public enum JSON { | |
public typealias D = Dictionary<String, Any> | |
public typealias A = Array<Dictionary<String, Any>> | |
case dictionary(D) | |
case array(A) | |
public init(_ dictionary: [String: Any]) { | |
self = .dictionary(dictionary) | |
} | |
public init(_ array: [[String: Any]]) { | |
self = .array(array) | |
} | |
public var dictionary: D? { | |
get { | |
switch self { | |
case .dictionary(let d): | |
return d | |
default: | |
return nil | |
} | |
} | |
} | |
public var array: A? { | |
get { | |
switch self { | |
case .array(let a): | |
return a | |
default: | |
return nil | |
} | |
} | |
} | |
} |
switch json {
case .array(let array):
case .dictionary(let dictionary):
}
Doesn't look better to me either.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage is not ideal yet tho. Suggestions?