错误“将非本地对象的地址传递给__autoreleasing参数以进行回写"; [英] error "Passing address of non-local object to __autoreleasing parameter for write-back"

查看:192
本文介绍了错误“将非本地对象的地址传递给__autoreleasing参数以进行回写";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将套接字客户端转换为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆