NSNumber arithmetic now has simpler syntax.

If you have ever wanted to perform quick and simple math operations on NSNumber values without having to pull out the value into a C data type and then putting it back into the NSNumber object, then you should know about boxed expressions in Objective C.

For example, to increment an NSNumber value, the old syntax was this:
// Assume x is a pointer to NSNumber with a value already assigned.
int tmpX = [x intValue];
x = [NSNumber numberWithInt:(tmpX + 1)];
Now becomes this:
x = @([x intValue] + 1);
I saw this on Stackoverflow, and as is usual on that site in regards to evolving technologies, an unpopular answer has the best info.

No comments:

Post a Comment