Why use NSNumber for key-value coding


eg, last part of chapter 30 says for non-object types use NSNumber to set variable.

[a setValue:@“280” forKey:@“voltage”];
returns the same result as
[a setValue:[NSNumber numberWithInt:280] forKey:@“voltage”];

so why do we use NSNumber for non-object types like instructed to do so in the chapter?


I think because setValue expects an object, so you wrap the number inside an NSNumber object: to make it an object. In your first line, you use @“280”, which is an NSString - also an object - that’ll work too, but why store a number as a string and loose the number functionality?!