C primitive types

The collections covered in this chapter only hold objects. What if you want a collection of floats or ints or pointers to structures? You can wrap common C primitive types in an object. There are two classes that are designed specifically for this purpose. NSNumber holds C number types. NSValue can hold a pointer and some types of structs.

For instance, if you wanted to put the numbers 4 and 5.6 into an array, you would use NSNumber:

N​S​M​u​t​a​b​l​e​A​r​r​a​y​ ​*​n​u​m​L​i​s​t​ ​=​ ​[​[​N​S​M​u​t​a​b​l​e​A​r​r​a​y​ ​a​l​l​o​c​]​ ​i​n​i​t​]​;​
[​n​u​m​L​i​s​t​ ​a​d​d​O​b​j​e​c​t​:​[​N​S​N​u​m​b​e​r​ ​n​u​m​b​e​r​W​i​t​h​I​n​t​:​4​]​]​;​
[​n​u​m​L​i​s​t​ ​a​d​d​O​b​j​e​c​t​:​[​N​S​N​u​m​b​e​r​ ​n​u​m​b​e​r​W​i​t​h​F​l​o​a​t​:​5​.​6​]​]​;​
..................Content has been hidden....................

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