I am a bit confused as to how arrays are handled in Objective-C. If I have an array such as
NSarray *myArray = [[NSArray alloc]
initWithObjects:@"N", @"N", @"N", @"N", @"N",
nil];
how do I change the first occurrence to "Y"?
You need an NSMutableArray ..
NSMutableArray *myArray = [[NSMutableArray alloc]
initWithObjects:@"N", @"N", @"N", @"N", @"N",
nil];
and then
[myArray replaceObjectAtIndex:0 withObject:@"Y"];
You can't, because NSArray
is immutable. But if you use NSMutableArray
instead, then you can. See replaceObjectAtIndex:withObject:
:
[myArray replaceObjectAtIndex:0 withObject:@"Y"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With