gpt4 book ai didi

iphone - ARC 转换的应用程序问题 : passing adress of non local object to _autoreleaseing parameter for write-back

转载 作者:行者123 更新时间:2023-12-03 20:27:52 30 4
gpt4 key购买 nike

我正在尝试使用 ios5 制作应用程序,我真的很困惑为什么会发生这种情况。有人可以帮我解释一下为什么出现错误时行中出现错误

将非本地对象的地址传递给__autoreleasing参数进行写回

以下调用导致错误

// note the following method returns _inStream and _outStream with a retain count that the caller must eventually release

if (![netService getInputStream:&_inStream outputStream:&_outStream]) {

NSLog(@"error in get input and output streams");
return;
}

我的类(class).h

NSInputStream      *_inStream;
NSOutputStream *_outStream;

@property (nonatomic, strong) NSInputStream *_inStream;
@property (nonatomic, strong) NSOutputStream *_outStream;

我的类(class).m

@synthesize _inStream;
@synthesize _outStream;

getInputStream是一个NSNetService类方法

请实现下面的 NSNetService 类 getInputStream

/* Retrieves streams from the NSNetService instance. The instance's delegate methods are not called. Returns YES if the streams requested are created successfully. Returns NO if or any reason the stream could not be created. If only one stream is desired, pass NULL for the address of the other stream. The streams that are created are not open, and are not scheduled in any run loop for any mode.
*/
- (BOOL)getInputStream:(NSInputStream **)inputStream outputStream:(NSOutputStream **)outputStream;

我在

中找到了相关帖子

non-local-object-to-autoreleasing-parameter

-pointer-ownership-issues

non-local-object-to-autoreleasing

from-ios-4-to-ios-5arc-passing-address

但是我无法找到问题

感谢有关此问题的任何帮助

谢谢

最佳答案

我找到了解决办法

我们开始吧。将变量创建为本地变量并将它们分配回原始变量。感谢@borreden 提供的富有洞察力的信息。

这是我最新的代码。

NSInputStream  *tempInput  = nil;
NSOutputStream *tempOutput = nil;

// note the following method returns _inStream and _outStream with a retain count that the caller must eventually release
if (![netService getInputStream:&tempInput outputStream:&tempOutput]) {

NSLog(@"error in get input and output streams");
return;
}
_inStream = tempInput;
_outStream = tempOutput;

关于iphone - ARC 转换的应用程序问题 : passing adress of non local object to _autoreleaseing parameter for write-back,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11826060/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com