ARC相当于自动释放?

Eon*_*nil 15 objective-c clang autorelease automatic-ref-counting

如果我有这个代码,

+ (MyCustomClass*) myCustomClass
{
    return [[[MyCustomClass alloc] init] autorelease];
}
Run Code Online (Sandbox Code Playgroud)

此代码保证返回的对象是自动释放的.ARC的相当于什么?

sha*_*oga 20

ARC中没有等价物,因为您不需要自己动手.它将在幕后发生,你不能自己做.

你只需使用 -

+ (MyCustomClass*) myCustomClass
{
    return [[MyCustomClass alloc] init];
}
Run Code Online (Sandbox Code Playgroud)

我建议你在2011年WWDC上观看ARC的介绍,因为它很简单.

看这里:https: //developer.apple.com/videos/wwdc/2011/

就像电影里的那个人说的那样 -

你不必再考虑它了(差不多)

  • 请注意,发生的情况取决于您为方法命名的方式. (4认同)

jus*_*tin 7

使用ARC进行编译时,只需将其写为:

+ (MyCustomClass *)myCustomClass
{
    return [[MyCustomClass alloc] init];
}
Run Code Online (Sandbox Code Playgroud)

并且编译器/运行时将为您处理其余的事情.