- (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).