Jesse Meyer
Jesse Meyer

Reputation: 315

How do I retain a mutable number?

I built a data system comprised of many multidimensional arrays which are accessed by an index which I store, but can change by the user. I naively presumed NSNumber could be modified but that is clearly not its purpose, so I'm a bit stuck. I cannot retain ints at all, as I lose them when I segue across views.

There's got to be a simple way of storing persistent ints but my investigations have left me a bit worried. Wat do?

The way my system works is straight forward is apt to:

@property (nonatomic, strong) NSMutableArray *data;
@property NSInteger *index; // this needs to be persistent across views

...

int index = *(_dataStorage.index);
NSSomeObject something;
[_dataStorage.data replaceObjectAtIndex:index withObject:something];

Upvotes: 0

Views: 112

Answers (1)

user529758
user529758

Reputation:

NSInteger *index; - Why? Why not NSInteger index? And why do you need to retain it? If you have an index, make that a read-write property, and whoever uses your object will be able to write

theObject.index = newIndex;

Upvotes: 1

Related Questions