ios - replace object at indexPath - big array with 12 sections -
i have array 12 sections , need replace value @ index. test code:
nsmutablearray *hm = [[nsmutablearray alloc] initwithobjects:@{@"first": @[@"test1", @"test2"]}, @{@"second": @[@"test1"]}, nil]; nslog(@"%@", [hm valueforkey:@"first"][0][0] ); [[hm valueforkey:@"first"][0] replaceobjectatindex:0 withobject:@"lol"]; nslog(@"%@", hm);
first nslog returns : test1
- ok
when replace - crash -[__nsarrayi replaceobjectatindex:withobject:]: unrecognized selector sent instance 0x7fde53d2f700
i need change test1 something.
wha doing wrong please?
nsmutablearray *hm = [[nsmutablearray alloc] initwithobjects:@{@"first": @[@"test1", @"test2"]}, @{@"second": @[@"test1"]}, nil]; nslog(@"%@", [hm valueforkey:@"first"][0][0] ); //your inner array immutable, change mutable , replace object, that's it. nsmutablearray *array = [[hm valueforkey:@"first"][0] mutablecopy]; [array replaceobjectatindex:0 withobject:@"lol"]; [hm replaceobjectatindex:0 withobject:array]; nslog(@"%@", hm);
Comments
Post a Comment