NSArray initWithObjects: save objects?

When adding objects to NSArray using "initWithObjects", someone can confirm that the elements are saved. I am sure they are, but cannot find that it is mentioned somewhere in relation to initWithObjects?

// CREATE DRINKS
Coffee *drink1 = [[Coffee alloc] initWithName:@"Flat White"];
Coffee *drink2 = [[Coffee alloc] initWithName:@"Cappucino"];
Coffee *drink3 = [[Coffee alloc] initWithName:@"Latte"];
Coffee *drink4 = [[Coffee alloc] initWithName:@"Mocha"];
Coffee *drink5 = [[Coffee alloc] initWithName:@"Hot Chocolate"];

// SET ARRAY
NSArray *tempArray = [[NSArray alloc] initWithObjects:drink_1, drink_2, drink_3, drink_4, drink_5, nil];
[self setCoffeeList:tempArray];

// CLEAN UP
[drink_1 release];
[drink_2 release];
[drink_3 release];
[drink_4 release];
[drink_5 release];
[tempArray release];
[super viewDidLoad];

greets gary

+3
source share
2 answers

initWithObjects saves all elements of the array.

initWithObjects: count:

  • (id) initWithObjects: (id *) count count: (NSUInteger) count; Availability: OpenStep

. . count ( ). , . -init ( , MacOS-X) , .

+5

, , . , . . . (, , . , , , .)

+4

Source: https://habr.com/ru/post/1771785/


All Articles