0

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

Chen-Tsu Lin
  • 22,876
  • 16
  • 53
  • 63

1 Answers1

1

This should work:

self.input?.delegate = self

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

Atomix
  • 13,427
  • 9
  • 38
  • 46