gpt4 book ai didi

swift - “NSInputStream”没有名为 'setDelegate' 的成员

转载 作者:行者123 更新时间:2023-11-30 10:22:04 25 4
gpt4 key购买 nike

我在 UIViewController 子类中使用 NSStreamDelegate 协议(protocol),

然后将 setDelegate 消息发送到 NSInputStream

var input : NSInputStream?
var output: NSOutputStream?

func connectToSocket(host: String, port: Int) {

NSStream.getStreamsToHostWithName(host, port: port, inputStream: &(self.input), outputStream: &(self.output)

let str = "test"
let data = str.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!

self.input?.setDelegate(self)

self.input?.open()
self.output?.open()

// ...

}

我收到“NSInputStream”没有名为“setDelegate”的成员错误消息

为什么我可以像下面的文档一样使用“setDelegate”?

https://developer.apple.com/library/prerelease/iOS/documentation/Cocoa/Reference/Foundation/Classes/NSStream_Class/index.html

最佳答案

这应该有效:

self.input?.delegate = self

看起来文档不是最新的。

关于swift - “NSInputStream”没有名为 'setDelegate' 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25617481/

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