Ouch.
That is how I feel after my encounter with NSJSONSerialization…
In the tutorial, there is instruction on how to handle a simple JSON object, but I needed something for nested content. Add that to Swift’s changing language, and (from what I have NOT been able to find), the poor documentation on the subject, I feel like I have been in a programming battle for my life!
My subjective point of view stems from not knowing the language and the feeling that the documentation seems to be written by programmers for other experienced programmers; not intended for those who are still trying to learn. Pepper in frustration, and viola! A perfect recipe of disdain.
I’m cranky and every little roadblock is pissing me off. There, I said it. I start to think, “Maybe I’m not smart enough, maybe I should quit.” This would be a mistake, quitting because I was frustrated means that I am beating myself, not that I can’t do it. Roadblocks can be a good thing. They can test you to see if you really want to go around, through or over it. Whichever way you choose, you know you want to be on the other side.
Here are the dirty results of banging my head against the wall for the weekend. The example is slightly modified as the I have edited out the api_key used in the original code. (Can’t have EVERYONE using my account! ) Instead, I have included a JSON file that emulates a portion of the results. Also included is the Swift file that parses the data. Yes I do have a github account. Why am I not using it? That is a very good question. We will investigate in the next post.
Other useful links…
http://stackoverflow.com/questions/24026305/how-do-i-parse-an-array-inside-parsed-json-in-swift
http://www.raywenderlich.com/82706/working-with-json-in-swift-tutorial
https://github.com/SwiftyJSON/SwiftyJSON (I did not use this approach, maybe next time)
http://www.learnswift.io/blog/2014/7/30/parsing-json-in-swift