ARC equivalent of autorelease?

后端 未结 2 1955
南旧
南旧 2021-02-19 06:30

If I have this code,

+ (MyCustomClass*) myCustomClass
{
    return [[[MyCustomClass alloc] init] autorelease];
}

This code guarantees

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-19 07:01

    There is no equivalent in ARC, as you don't need to do it yourself. it will happen behind the scenes and you are not allowed to do it your self.

    You simply use -

    + (MyCustomClass*) myCustomClass
    {
        return [[MyCustomClass alloc] init];
    }
    

    I suggest you to watch the ARC introduction in the 2011 WWDC as it very simple when you get it.

    Look here: https://developer.apple.com/videos/wwdc/2011/

    And as the guy in the movie says -

    You don't have to think about it any more (almost)

提交回复
热议问题