Created
December 16, 2016 01:45
-
-
Save khanlou/e03e86abba9616d31da2041544a384ff 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
| protocol JSONValueConvertible { | |
| var jsonValue: JSONValue { get } | |
| } | |
| protocol JSONValue: JSONValueConvertible { } | |
| extension JSONValue { | |
| var jsonValue: JSONValue { | |
| return self | |
| } | |
| } | |
| extension String: JSONValue { } | |
| extension Int: JSONValue { } | |
| extension Double: JSONValue { } | |
| extension Bool: JSONValue { } | |
| extension Array: JSONValue { } | |
| extension Array where Element: JSONValueConvertible { | |
| var jsonValue: JSONValue { | |
| return self.map({ $0.jsonValue }) | |
| } | |
| } | |
| struct Convertible: JSONValueConvertible { | |
| let string: String | |
| var jsonValue: JSONValue { | |
| return string | |
| } | |
| } | |
| let a = [Convertible(string: "bing")] | |
| let b = a.jsonValue | |
| print(a) | |
| print(b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment