views:

673

answers:

2

I have a NSMutableArray which i am initializing from a plist with strings.

but when i try to do objectAtIndex or removeObjectAtIndex on that array, I'm getting the warning "NSMutableArray may not respond to...." and it also fails at execution.

how do i sovle this?

thx

A: 

It looks like you either misspelled the method name, or (more likely), the object isn't actually an NSMutableArray.

Here's one way to check the type. This will only work in the simulator, but it could be helpful in solving your problem:

#import <objc/runtime.h>

// Later, when you've got the object x that you want to be an NSMutableArray:
NSLog("The type of x is %s", class_getName([x class]));

Check the debug output of your app when it gets to that line (shortcut: command-shift-R in xcode).

Also, I'm sure you already know this, but method names in objective-C are case sensitive, and technically include the colon at the end when there are arguments. So a valid call would look like this:

id gottenObject = [x objectAtIndex:0];

Sorry if that seems unnecessary to mention, but I thought I'd be more comprehensive in my answer, just in case you used a capital O by mistake or something.

Tyler
+1  A: 

I'm guessing without the relevant code, but if you store an NSMutableArray into an NSArray* variable, the compiler uses static typing based on the variable type and assumes the object is an NSArray and thus immutable. (Hence, the "may not respond to..." warnings.) Conversely, you could be trying to store an NSArray in an NSMutableArray* variable, which would cause failure at runtime as well. It's quite hard to say without context, but those are things to explore.

Quinn Taylor