Collections and nil

You are not allowed to add nil to any of the collection classes we have covered. What if you need to put that idea of nothingness, a hole, into a collection? There is a class called NSNull. There is exactly one instance of NSNull, and it is an object that represents nothingness. Here is an example:

N​S​M​u​t​a​b​l​e​A​r​r​a​y​ ​*​h​o​t​e​l​ ​=​ ​[​[​N​S​M​u​t​a​b​l​e​A​r​r​a​y​ ​a​l​l​o​c​]​ ​i​n​i​t​]​;​ /​/​ ​L​o​b​b​y​ ​o​n​ ​t​h​e​ ​g​r​o​u​n​d​ ​f​l​o​o​r​ [​h​o​t​e​l​ ​a​d​d​O​b​j​e​c​t​:​l​o​b​b​y​]​;​ /​/​ ​P​o​o​l​ ​o​n​ ​t​h​e​ ​s​e​c​o​n​d​ [​h​o​t​e​l​ ​a​d​d​O​b​j​e​c​t​:​p​o​o​l​]​;​ /​/​ ​T​h​e​ ​t​h​i​r​d​ ​f​l​o​o​r​ ​h​a​s​ ​n​o​t​ ​b​e​e​n​ ​b​u​i​l​t​ ​o​u​t​ [​h​o​t​e​l​ ​a​d​d​O​b​j​e​c​t​:​[​N​S​N​u​l​l​ ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.