简体   繁体   中英

NSMutableArray not responding to removeObjectAtIndex:

I think i've run into a confused state where i'm doing something fundamentally wrong, but i cannot understand what and why this is happening.

Picture 1: A property of a My class. A NSMutableArray.

属性

Picture2: The code block i want to execute, i want to remove the eleventh object.

码

Picture3: The debug console shows me that i have 30 objects within my array.

控制台声明

And now, here i was, thinking that this would be an easy task. Since, i've removed and replaced objects at indexes in other NSMutableArrays within my source-code. Here comes Picture4: 堆栈跟踪

I believe this is telling me that NSMutableArray doesn't respond to removeObjectAtIndex.

Does anyone know what in the heck i'm doing wrong? I'm totally confused.

And no, this is not homework...even if one could believe so. I do.


EDIT : The error was made during parsing of the objects that went into the dagArray.

Instead of [tempPeriod.dagArray addObject:object] i was doing something completely different.

I was working with a different array and added objects to that array, and when the parser was finished i used tempPeriod.dagArray = [theOtherArray copy] which resulted in this error. theOtherArray was still a NSMutableArray which still confused me. But my best guess is that copy does something with the NSMutableArray rendering it unable to perform those selectors. But i could be completely wrong.

Thanks for shining some thoughts into this.

actually it says that NSArray doesn't respond to removeObjectAtIndex. Which would be true. Could it be that you define it as NSMutableArray , but initialise it in a wrong way? Where do you init the array, is it possible that the current array is actually a NSArray ?

because:

NSMutableArray *anArray = [[NSArray alloc] initWithObject:anObject];

is possible, but would result in runtime errors when you select the wrong selectors.

You need to use -mutableCopy if you want a mutable copy of an array. Using -copy , even on a mutable array, will give you an immutable array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM