1

There has to be.

Two objects, each with an NSNumber property. I want to add the value of one into the other.

I came up with

int count = [[cat resultCount] intValue];
count += [[allTours resultCount] intValue];
[allTours setResultCount:[NSNumber numberWithInt:count]];

Which is ridiculous. But I wasn't sure I could just randomly add NSNumber objects together given how temperamental they are with logical comparisons.

Anyone got a better way? (Not using NSNumber, unfortunately, is not an option. I would if I could)

edit

This is technically a duplicate of How to add two NSNumber objects? but I don't know how to flag it as such or whatever...

Community
  • 1
  • 1
M. Ryan
  • 6,973
  • 11
  • 52
  • 76

1 Answers1

2

You can combine it into one line, but there is nothing you can do about NSNumber - it is a class, and you can't perform math operations on classes:

[allTours setResultCount:[NSNumber numberWithInt:([[cat resultCount]intValue] + [[allTours resultCount]intValue])]];
Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144