O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Safely Working with Untyped Data Structures

Congratulations, it works! But are you finished? Your application already detects errors from JSON parsing (converting the received JSON data into a tree of NSDictionary, NSArray, and so forth), but it does not check that the structure of this data satisfies the expectations of the app’s code.

As it stands, the code makes some assumptions about the structure of the JSON. Consider these lines:

 ​ ​ ​ ​ ​ ​ ​ ​l​e​t​ ​t​i​t​l​e​ ​=​ ​c​o​u​r​s​e​D​i​c​t​[​"​t​i​t​l​e​"​]​ ​a​s​!​ ​S​t​r​i​n​g​ ​ ​ ​ ​ ​ ​ ​ ​l​e​t​ ​u​r​l​S​t​r​i​n​g​ ​=​ ​c​o​u​r​s​e​D​i​c​t​[​"​u​r​l​"​]​ ​a​s​!​ ​S​t​r​i​n​g​ ​ ​ ​ ​ ​ ​ ​ ​l​e​t​ ​u​p​c​o​m​i​n​g​A​r​r​a​y​ ​=​ ​c​o​u​r​s​e​D​i​c​t​[​"​u​p​c​o​m​i​n​g​"​]​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required