When you have to deal with numbers for anything else than short computation, is it a loss of time and energy using always NSNumber ?
What’s the best approach ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well,
NSNumbergenerally has to go through the allocation and reference counting hoops to create, so that takes a lot longer than creating a float on the stack.As well,
NSNumberis an immutable type, so it doesn’t make a whole lot of sense to set it often because every time it changes, you have to allocate a new instance. There are a few optimizations they make, but it’s still huge overhead relative to creating a float on the stack. Using builtins will also require less memory thanNSNumbermore often than the other way around.I just use builtins (e.g.
float,int) unless I need anNSNumber. Details and rationale here.