March 2017
Intermediate to advanced
226 pages
5h 13m
English
Although cascaded bindings avoid Swift’s “pyramids of doom,”[37] they may lead instead to “constipated blocks of horror.” When faced with excess serial bindings, interleave statements with newlines and comments:
| | guard |
| | // Access JSON as dictionary |
| | let json = json as? NSDictionary, |
| | |
| | // Retrieve results array |
| | let resultsList = json["results"] as? NSArray, |
| | |
| | // Extract first item |
| | let results = resultsList.firstObject as? NSDictionary, |
| | |
| | // Extract name and price |
| | let name = results["trackName"] as? String, |
| | let price = results["price"] as? NSNumber |
| | |
| | else { return nil } |
Just because conditions can coexist within a single statement doesn’t mean ...
Read now
Unlock full access