Question

NSLog(@"Size of array: %i", ([HistoricDatesArray [23] count]));
HistoricDatesArray [23] = HistoricDatesArray [23][1];
NSLog(@"Size of array: %i", ([HistoricDatesArray [23] count]));

As soon as the second NSLog tries to execute:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString count]: unrecognized selector sent to instance 0x728c7f0'

historicDatesArrray is a NSMutableArray. I can read(NSString) the contents of historicDatesArray[23], but can't count the elements?

I no longer need the object at HistoricDatesArray[23][0] and want to assign the object at HistoricDatesArray[23][1] to HistoricDatesArray[23], which I tested and works, but why can't I use 'count' to get the size of the array?

How can I convert the 2d NSMutableArray back to a 1d NSMutableArray?

Was it helpful?

Solution

I think the problem is that the HistoricDatesArray [23] is no more an array .It is currently holding a string value and It wont have the count property.That makes the issue

FirstLine:

Object at HistoricDatesArray index 23 is an Array,It has values as [23][1] ,[23][2]...etc

So you will have value for the count operation

NSLog(@"Size of array: %i", ([HistoricDatesArray [23] count]));

The value at the HistoricDatesArray [23][1] is a string.

second Line:

HistoricDatesArray [23] = HistoricDatesArray [23][1];

Here you are changing the value of array index [23] from an array to string.and hence there is no more an array at index [23] .It represent a string value

Third Line:

NSLog(@"Size of array: %i", ([HistoricDatesArray [23] count]));

Trying to log the count property where it is for an array,but the value at index 23 is just a string and hence the crash

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top