Passing address of non-local object to __autoreleasing parameter for write-back

在希望通过函数的參数返回Objective-C对象的时候。遇到了这个问题

错误代码例如以下:

- (void)methodA:(NSString **)string<span style="white-space:pre">	</span>// 事实上。这里的參数实际类型是:(NSString * __autoreleasing * )string
{
    *string = XXX;
}

正确的使用方法是

- (void)methodA:(NSString * __strong *)string
{
    *string = XXX;
}


调用的时候:

NSString *strongString;
[object methodA:&strongString];



Ref:

1.

http://blog.csdn.net/chuanyituoku/article/details/17371807

我的这篇文章的最后部分:

Returning a Result as the Argument
有具体介绍 (看过一遍、而且理解 事实上是远远不够的。要吃过苦头才干记牢。。。)


2.

http://codego.net/402513/

原文地址:https://www.cnblogs.com/cxchanpin/p/6732927.html