Using Generics

suggest change

For added safety we can define the type of object that the array contains:

NSArray<NSString *> *colors = @[@"Red", @"Green", @"Blue", @"Yellow"];
NSMutableArray<NSString *> *myColors = [NSMutableArray arrayWithArray:colors];
[myColors addObject:@"Orange"]; // OK
[myColors addObject:[UIColor purpleColor]]; // "Incompatible pointer type" warning

It should be noted that this is checked during compilation time only.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


NSArray:
*Using Generics

Table Of Contents