【问题标题】:'NSInputStream' does not have a member named 'setDelegate'“NSInputStream”没有名为“setDelegate”的成员
【发布时间】:2014-09-02 06:54:49
【问题描述】:

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

然后将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

【问题讨论】:

    标签: swift nsstream nsinputstream


    【解决方案1】:

    这应该可行:

    self.input?.delegate = self
    

    文档似乎不是最新的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-23
      • 2014-11-09
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      • 2013-05-23
      相关资源
      最近更新 更多