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?
This should work:
self.input?.delegate = self
Looks like the documentation isn't quite up to date.