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’s 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​ ​n​u​l​l​]​]​;​

/​/​ ​B​e​d​r​o​o​m​s​ ​o​n​ ​f​o​u​r​t​h​ ​f​l​o​o​r​
[​h​o​t​e​l​ ​a​d​d​O​b​j​e​c​t​:​b​e​d​r​o​o​m​s​]​;​
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset