Tell me how you can implement it. We have a link to JSON
urlToRequest = = "formatio.ru/api/v1/events?q=&city_id=&tag_id=&start_date=2015-01-01&end_date"
We have the first function: Accepts a URL written as a String. Returns an object of type NSData (As I understand it, after execution, there is simply raw data)
func getJSON(urlToRequest: String) -> NSData{ return NSData(contentsOfURL: NSURL(string: urlToRequest)) }
Next, we have 2 function that will process this "raw" data (parsit) Accepts an NSData object, returns an object of type NSDictionary (Choose this data type since it is best suited for storing JSON's)
func parseJSON(inputData: NSData) -> NSDictionary{ var error: NSError? var dictionaryFullJson: NSDictionary = NSJSONSerialization.JSONObjectWithData(inputData, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary return dictionaryFullJson }
Further, as I understand it, 1) we must write our dictionaryFullJson to a variable of type NSDictionary in the viewDidLoad () function already (Is this the main function?)
override func viewDidLoad() { super.viewDidLoad() let storeJSONFromApi = parseJSON(getJSON(urlToRequest: String)) }
Everything, after launching the application, we have our Json placed in the NSDictioanary in the storeJSONFromApi constant.
Do I understand everything correctly?
Next you need to bring JSON from Dictionary to TableView. How can this be implemented?
Or, after all, “The code written in the global domain is used as an entry point for the program” and you just have to write beyond the boundaries of other functions
let storeJSONFromApi = parseJSON(getJSON(urlToRequest: String))
and it will be executed, as will be the entry point to the program?