@ [obj1,obj2]创建什么样的对象? [英] What kind of object does @[obj1, obj2] create?

查看:105
本文介绍了@ [obj1,obj2]创建什么样的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下问题:

NSArray *array = @[object1, object2];

似乎正在创建NSArray,但是此数组实例是自动释放的对象,还是我必须释放它?

It seems to be creating an NSArray, but is this array instance an autoreleased object, or must I release it?

推荐答案

这是xcode 4.4及更高版本附带的编译器中可用的新集合文字

This is a new collection literal available in the compiler that ship with xcode 4.4 and above

@[object1, object2];

等同于

[NSArray arrayWithObjects:object1, object2, nil];

是的,它是一个自动释放的对象,如果需要保留此对象,则可以

so yes, it is an autoreleased object, if you need this to be retained, you can do

myRetainedArray = [@[object1, object2] retain];

此问题具有很好地描述了所有新的文字

this question has a good description of all of the new literals

这篇关于@ [obj1,obj2]创建什么样的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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