views:

80

answers:

1

Hi guys!

Now I'm working on an iPhone project and I'm using instances of the class NSMutableArray and suddenly, with no reason, at execution time the NSMutableArray converts into a UICachedDeviceRGBColor becoming unusable.

I do not know what to do, the same object had been working fine until today.

I got this error:

*** -[UICachedDeviceRGBColor count]: unrecognized selector sent to instance 0x4b3e440
+5  A: 

Next time, stick your code in your question, not the comment. Here it is nicely formatted:

NSMutableArray *currentIngsGroup = [[NSMutableArray alloc] init];
currentIngsGroup = (NSMutableArray *)[allIngredientGroups objectAtIndex:0];
NSLog(@"accesing array %d", [currentIngsGroup count]);

Normally, I would say that the symptom you describe indicates that you are over-releasing something. The code, though, demonstrates a fundamental lack of understanding of Objective-C. I would suggest reading the Introduction to Objective-C document.

In particular, you are allocating an instance of NSMutableArray in the first line of code. The second line, though, immediately overwrites the mutable array reference with a reference to whatever object is at index 0 of the allIngredientGroups array.

The (NSMutableArray *) is totally unnecessary. It won't force whatever object is in the array to be a mutable array and, since -objectAtIndex: returns an (id) a cast isn't necessary.

BTW: The array allocated on the first line is being leaked. Again, read the introduction to objective-c to understand why.

bbum
Thanks bbum!Sorry because I didn't place my code in the correct place and I didn't explain that the code lines are was taken from the entire main controller (they are not together). Thanks a lot for your help. I couldn't make the app to work again, thanks God I had a working version at the SVN. Thanks again Alejandra :)
Alejandra Gonzalez
Happy to help. Seriously -- go read the intro guide. It is good stuff!!
bbum