NSArray initWithObjects:保留对象? [英] Does NSArray initWithObjects: retain objects?

查看:110
本文介绍了NSArray initWithObjects:保留对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用initWithObjects将对象添加到NSArray时,任何人都可以确认项目是否保留。我确定他们是,但不能找到它提到任何地方关于initWithObjects?

When adding objects to an NSArray using "initWithObjects" can anyone confirm for me that the items are retained. I am pretty sure they are, but can't find it mentioned anywhere with regards 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];

欢呼Gary

推荐答案

initWithObjects保留数组中的所有项目。

initWithObjects retains all items in the array.

initWithObjects:count:

initWithObjects: count:


  • (id)initWithObjects:(id *)对象计数:(NSUInteger)count;
    可用性:OpenStep

这是类的指定初始化程序。
子类必须覆盖此方法。
这应该用count(可能为零)对象初始化数组。
保留放置在数组中的每个对象。
调用-init(它只保留MacOS-X兼容性),需要在子类中重新实现,以使所有其他初始化工作。

This is a designated initialiser for the class. Subclasses must override this method. This should initialize the array with count (may be zero) objects. Retains each object placed in the array. Calls -init (which does nothing but maintain MacOS-X compatibility), and needs to be re-implemented in subclasses in order to have all other initialisers work.

这篇关于NSArray initWithObjects:保留对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆