NSLog(@" --- object id = %ld --- ",
(long) [mp_list objectAtIndex : 0]);
target_coordinate_2D = [[mp_list objectAtIndex : 0] coordinate];
// Some test code here which verifies that target_coordinate_2D
// gets assigned a valid "coordinate" value.
[mapView addAnnotation : [mp_list objectAtIndex : 0]];
Consider the above 3 statements :
According to documentation, the NSArray’s method “objectAtIndex” should return an object. My understanding is the value returned is a numeric pointer to the object.
But what I got is :
--- object id = 0 ---
'NSInvalidArgumentException', reason: '-[... addObject:]: attempt to insert nil'
My questions are :
1
Why “object id” is nil ? Since target_coordinate_2D got assigned a valid value,
[mp_list objectAtIndex : 0] should indeed be a valid object with a valid “coordinate”
property.
2
On the last statement, I wish to add the object in mp_list to mapView. The NS Exception
thrown by the simulator is consistent of the fact that “[mp_list objectAtIndex : 0]” is
indeed nil. So there must be something I have missed about NSArray. What should be
done in order to assign an object to an array from another array ?
Hope that somebody knowledgable in this area can help …
It sounds like
mp_listitself isnil, which is why[mp_list objectAtIndex:0]is returningnil(because messagingnilreturnsnil).