When should I use primitives in Objective-C instead of NSValue
subclasses? This code is certainly cleaner (I think) than using NSNumber:
float width = sliderOne.frame.size.width;
float totalWidth = width * 2 + 10;
but are there any drawbacks? Also, is it correct that I don't need to call release
or anything with primitives? Does the memory get freed when they go out of scope, then?
The basic types are preferred. Only use the NSNumber and NSValue objects when you have to pass them as an object.
The only drawback to the primitive types are that you can't pass them as an object.
Primitive types can be allocated on the stack (local variables) or the heap (w/malloc). Objects can only be allocated on the heap, which is more expensive that stack allocation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With