I have a very weird situation with NSMutableArray when trying to run a project on an ios 8.4 simulator. The project is non-arc and there's a lot of code, but the summary of the problem would be as follows:
- i have an NSMutableArray *months instance variable
- there is a method "populate" that populates this array
- there is a method "monthCount" (just an alias of [months count])
Code for monthCount:
NSLog(@"months.count = %i", [months count]);
return [months count];
Here's where it all goes weird: in the "populate" method i'm creating dictionaries and adding them to the "months" array. After adding a new object i do the following:
NSLog(@"count after adding: %i", [months count]);
NSLog(@"monthCount returned: %i", [self monthCount]);
For some reason, only [months count] works from the "populate" method. The [self monthCount] always returns "1". Here's something stranger: The monthCount method sees the count of months correctly (that is the NSLog contained in this function outputs the correct count), but after i return and print out the value in the "populate" method - it becomes "1".
I've also used the debugger to test if "populate" and "monthCount" methods are actually accessing the same array and they do. The same code also runs perfectly on my ios7 device (so perhaps it's just a simulator thing, but i can't test on a device right now). Does anyone have any clue as to what's going on here?
monthsis a property on your class, how was it declared...strongorcopy? Please post yourpopulateandmonthCountin their entirety.