Do all class methods return an auto-implemented object?

I am rereading the first few chapters of Cocoa Programming for Mac OS X, and the author claims that one of the methods of the class NSCalendarDatereturns an object with auto-implementation. I always assumed that all methods of the class return an auto-implemented object (since there is none alloc).

Are there any class methods that you should specifically keep?

Thanks.

+3
source share
4 answers

Class methods, like instance methods, must adhere to Cocoa standard memory management rules .

, , , "alloc" "new" "" (, alloc, newObject mutableCopy), . . , .

, - . , "alloc" "new" "copy". , , iVar - .

+22

. . [NSMutableArray array] [[[[NSMutableArray alloc] init] autorelease].

, , , . . menthod alloc *, copy, new * name, . 1 .

+1

, , - - ( , ..) (void). Objective-C , , ( , / ).

, @Joey . , , , . , .

+1

General rule: if the method name contains alloc, new or copy, then you own it. Otherwise, it can be auto-implemented or taken care of by someone else, that is, you do not own it, so you do not need to worry about it.

0
source

Source: https://habr.com/ru/post/1716886/


All Articles