P
P
Petrushka2015-05-10 00:12:16
Objective-C
Petrushka, 2015-05-10 00:12:16

How to add a number to an array element?

Good day, I have an array (NSArray)
self.myArray = [NSArray arrayWithObjects:@0,@0,nil]; // 0,0
how now to add 1 (++) to 1 element? // 1.0
Have to work with SMI arrays?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav H, 2015-05-10
@petruska

NSArray is static.
The first thing that came to mind was something like this.

NSMutableArray *array = ;      
NSLog(@"array %@",array);// 0, 0
[array replaceObjectAtIndex:0 withObject:@([array[0] intValue] +1)];
NSLog(@"array %@",array);// 1, 0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question