Here is my code
I’m looping through the array and adding to the NSNumber.
NSNumber *totalValue = 0;
NSMutableArray *items = [10, 35, 25]; // Just for demo
for (int i=0; i < items.count; i++)
{
totalValue = totalValue + [items objectAtIndex:i] // How do I add the totalValue?
}
Can someone help me with this code?
NSNumberis an Objective-C class. Unlike in C++, operators cannot be overloaded in Objective-C so you have to call everything manually.You might want to use
NSIntegerinstead, which is faster (especially for a large number of items: memory allocation is expensive):You should really only use
NSNumberwhen you need an Objective-C object, like in an array, dictionary or coder. Otherwise, use a POD likeNSInteger,intordouble.