gpt4 book ai didi

objective-c - ARC 不允许将间接指针转换为指向 'CFReadStreamRef *' 的 Objective-C 指针

转载 作者:太空狗 更新时间:2023-10-30 03:44:40 27 4
gpt4 key购买 nike

我想将 CFStreamCreatePairWithSocketToHostNSInputOutputStream 一起使用。我有两个 ivars NSInputStream *_inputStreamNSOutputStream *_outputStream

下面给了我两条错误信息:

CFStreamCreatePairWithSocketToHost(NULL,
(__bridge_retained CFStringRef)self.hostname, self.port,
(CFReadStreamRef *)&_inputStream, (CFWriteStreamRef *)&_outputStream);

error: cast of an indirect pointer to an Objective-C pointer to 'CFReadStreamRef *' (aka 'struct __CFReadStream **') is disallowed with ARC
error: cast of an indirect pointer to an Objective-C pointer to 'CFWriteStreamRef *' (aka 'struct __CFWriteStream **') is disallowed with ARC

我该如何解决这个问题?我尝试使用 __bridge 但我收到了类似的错误消息。

最佳答案

传递指向实际 CFReadStreamRefCFWriteStreamRef 变量的指针,然后在分配给您的 NSType 时进行转换。基本上:

CFThingRef cfThing = NULL;
CFFunctionGetThing(&cfThing);
NSThing * nsThing = cfThing;

当然,您必须添加适当的桥接转换并为 cfThing 执行所有适当的引用计数操作。

关于objective-c - ARC 不允许将间接指针转换为指向 'CFReadStreamRef *' 的 Objective-C 指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8834383/

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