swiftnsstreamnsinputstream

'NSInputStream' does not have a member named 'setDelegate'


I use NSStreamDelegate protocol in A UIViewController subclass,

And then send setDelegate message to a 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()

    // ...

}

I got a 'NSInputStream' does not have a member named 'setDelegate' error message

Why can I use 'setDelegate'` like below document?

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


Solution

  • This should work:

    self.input?.delegate = self
    

    Looks like the documentation isn't quite up to date.