错误“将非本地对象的地址传递给__autoreleasing参数以进行回写"; [英] error "Passing address of non-local object to __autoreleasing parameter for write-back"
问题描述
我正在将套接字客户端转换为ARC:
I'm converting my socket client to ARC:
- (id)initWithHostname:(NSString *)hostname AndPort:(NSInteger)port
{
if((self = [super init]))
{
oBuffer = [[NSMutableData alloc] init];
iBuffer = [[NSMutableData alloc] init];
iStream = [[NSInputStream alloc] init];
oStream = [[NSOutputStream alloc] init];
[NSStream getStreamsToHost:[NSHost hostWithName:hostname] port:port inputStream:&iStream outputStream:&oStream];
...
}
return self;
}
我得到的错误是:
error: Automatic Reference Counting Issue: Passing address of non-local object to __autoreleasing parameter for write-back
在&iStream
和&oStream
的这一行:
[NSStream getStreamsToHost:[NSHost hostWithName:hostname] port:port inputStream:&iStream outputStream:&oStream];
有帮助吗?
推荐答案
此错误通常是由于将非局部变量地址传递给方法所致.因为默认情况下变量被声明为__strong
,而方法的参数是__autoreleasing
,所以将调用的方法的参数声明为__strong
,例如:-(void)method:(id * __strong *)param
.
This error is usually due to the non local variable address is passed to a method. Because the variable is declared as __strong
by default, while the parameter of the method is __autoreleasing
, so declare the parameter of the method invoked as __strong
,like this: -(void)method:(id * __strong *)param
.
请注意,头文件(.h
文件)中的方法必须声明为与.m
文件相同.
Note that the method in the header file (.h
file) must be declared as the same of the .m
file.
这篇关于错误“将非本地对象的地址传递给__autoreleasing参数以进行回写";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!