' NSInputStream'没有名为' setDelegate'的成员

时间:2014-09-02 06:54:49

标签: swift nsstream nsinputstream

我在A NSStreamDelegate子类中使用UIViewController协议,

然后将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' does not have a member named 'setDelegate'错误消息

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

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

1 个答案:

答案 0 :(得分:1)

这应该有效:

self.input?.delegate = self

看起来文档不是最新的。