- (id) foo __attribute((ns_returns_retained)); //返回值retain +1, init,new,alloc,copy,mutablecopy default are this - (id) foo __attribute((ns_returns_not_retained)); //返回指針弱引用, - (id) foo __attribute((ns_returns_autoreleased)); //返回autorlease, except default, are this
復制代碼 init開頭的方法有一個規定,一定要返回id或父類,子類的指針,不然要有warning.
這兒是原話:
init methods must be instance methods and must return an Objective-C pointer type. Additionally, a program is ill-formed if it declares or contains a call to an init method whose return type is neither id nor a pointer to a super-class or sub-class of the declaring class (if the method was declared on a class) or the static receiver type of the call (if it was declared on a protocol).