Difference between [[NSDate date] retain] and [[NSDate alloc] init]

前端 未结 5 1916
醉梦人生
醉梦人生 2021-01-03 10:36

As both of the following serves the same purpose,

today = [[NSDate date] retain];    

and

today = [[NSDate alloc] init]; 
<         


        
5条回答
  •  情书的邮戳
    2021-01-03 11:22

    There is essentially no difference, except that the former puts the object in the autorelease pool unnecessarily.

    If I want to retain the object after creating it, and an -init style method is available for the class, I almost always choose that over the convenience constructor plus -retain.

提交回复
热议问题