hi am working with NSArrays using foundation tool and i have wrote the following code
-(void)simplearrays
{
NSMutableArray *arr = [NSMutableArray array
NSArray
and NSMutableArray
aren't just synonyms for C arrays, they are container objects with their own interfaces. If you want to insert objects into one, it needs to be an NSMutableArray
and you need to call mutator methods such as addObject:
. You can't just use the []
operator. Similarly for reading objects out -- you have to go through methods such as objectAtIndex:
.
(Note that your code is sort-of syntactically valid, which is why the compiler lets you do it at all -- you're using []
to dereference a pointer. But it is semantically very wrong. It will not do what you want and will likely trash memory in potentially disastrous ways.)