Last active
August 8, 2017 17:49
-
-
Save AntonTheDev/e498b82917a9a5b81888be6ab08abb8a to your computer and use it in GitHub Desktop.
De-obfuscation of Contentful's model back to JSON
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
| extension Entry { | |
| fileprivate static let contenfulEntryIDKey = "id" | |
| var jsonResponse : [String : Any] { | |
| var entryFields = fields | |
| entryFields[Entry.contenfulEntryIDKey] = id | |
| for (key, value) in entryFields | |
| { | |
| if let linkedArray = value as? [Link] | |
| { | |
| entryFields[key] = jsonArray(for : linkedArray) | |
| } | |
| } | |
| return entryFields | |
| } | |
| fileprivate func jsonArray(for linkedArray : [Link]) -> [[String : Any]] { | |
| return linkedArray.filter { | |
| $0.entry != nil | |
| }.map { | |
| $0.entry!.jsonResponse | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment