初始化对象 [英] Initializing objects

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

问题描述


可能重复:

[NSMutableArray数组]与[[NSMutableArray alloc] init]之间的区别

使用Objective-C /可可粉,有什么区别:

Using Objective-C/Cocoa, what's the difference between:

NSMutableData *myData = [NSMutableData data];
NSMutableString *myString = [NSMutableString string];

NSMutableData *myData = [[NSMutableData alloc] init];
NSMutableString *myString = [[NSMutableString alloc] init];

据我所知,它们似乎具有相同的最终结果?

They seem to have the same end result as far as I can tell?

推荐答案

[NSMutableData数据]被称为帮助器,请查看此帖子,可可中的助手功能

[NSMutableData data] is referred to as a helper, check this post, Helper functions in Cocoa

助手通常会为您处理内存管理,也可以用于返回

Helpers generally take care of the memory management for your, can also be used to return singletons.

[[NSMutableData] alloc] init],则您负责内存管理。

[[NSMutableData] alloc] init], you are responsible for memory management.

您正在使用ARC,而不必释放对象,它会为您完成。

Although if you are using ARC you don't have to release your objects, it does it for you.

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

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