// Most common use id mutableArray = [NSMutableArray array]; // May not be what you want id array = [NSArray array];
id array = [NSMutableArray arrayWithObjects: @"Plates", @"Plasticware", @"Napkins", nil];
id mutableArray = [NSMutableArray arrayWithArray:@("A", "B", "C")];
creates an NSMutableArray from a constant NSArray object.
id guestArray = @("Suzy", "Alice", "John", "Peggy", "David"); id sortedArray = [guestArray sortedArrayUsingSelector:@"compare:"];
creates the NSArray sortedArray containing the string "Alice" at index 0, "David" at index 1, and so on.
id guestArray = [NSMutableArray arrayWithContentsOfFile:path]; [guestArray addObject:newGuest]; [guestArray writeToFile:path atomically:YES];
creates guestArray with the contents of the specified file, adds a new guest, and saves the changes to the same file.
id array = [NSMutableArray arrayWithObjects: @"Plates", @"Plasticware", @"Napkins", nil]; id description = [array description];
produces the string "(Plates, Plasticware, Napkins)".
id commaString = @"A, B, C"; id array = [string componentsSeparatedByString:@","]; id dashString = [array componentsJoinedByString:@"-"];
creates the NSString dashString with the contents "A-B-C".
Table of Contents Next Section