gpt4 book ai didi

ios - 无法将表达式的类型 'Void' 转换为类型 'CFAllocator!'

转载 作者:行者123 更新时间:2023-11-28 07:18:27 25 4
gpt4 key购买 nike

var readStream:CFReadStream?
var writeStream:CFWriteStream?
var request: NSMutableURLRequest = NSMutableURLRequest()

var host = request.URL.host
var port = request.URL.port.unsignedIntegerValue

CFStreamCreatePairWithSocketToHost(nil, nil, port, readStream, writeStream)
^ "Cannot convert the expression's type Void to type CFAllocator!"

为什么假设我将其类型更改为“CFAllocator!”。我尝试更改输入值,但它一直出现相同的错误。

最佳答案

想通了。

var host: CFString = NSString(string: request.URL.host)
var port: UInt32 = UInt32(request.URL.port.unsignedIntegerValue)

var readStream: Unmanaged<CFReadStream>?
var writeStream: Unmanaged<CFWriteStream>?

CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, host, port, &readStream, &writeStream)

inputStream = readStream!.takeUnretainedValue()
outputStream = writeStream!.takeUnretainedValue()

inputStream!.delegate = self
outputStream!.delegate = self

inputStream!.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
outputStream!.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)

inputStream!.open()
outputStream!.open()

出现此错误的原因是因为所有值都必须是“CreatePairWithSocket..”函数要求的确切类型。我做了一些研究,也发现这很有帮助 question .

关于ios - 无法将表达式的类型 'Void' 转换为类型 'CFAllocator!',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24021875/

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