任何想到这个问题的人都将不胜感激!
代码如下:
import UIKitclass VIEwController: UIVIEwController,StreamDelegate { let addr:String = "52.34.56.78" let port:Int = 1234 var inputStream: inputStream? var outputStream: OutputStream? overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() self.connect(host: addr,port: port) } func connect(host: String,port: Int) { Stream.getStreamsToHost(withname: host,port: port,inputStream: &inputStream,outputStream: &outputStream) if inputStream != nil && outputStream != nil { inputStream!.delegate = self outputStream!.delegate = self inputStream!.schedule(in: RunLoop.main,forMode: RunLoopMode.defaultRunLoopMode) outputStream!.schedule(in: RunLoop.main,forMode: RunLoopMode.defaultRunLoopMode) inputStream!.open() outputStream!.open() print("successfully connected") } else { print("connection unsuccessful") } } func stream(aStream: Stream,handleEvent eventCode: Stream.Event) { if aStream === inputStream { switch eventCode { case Stream.Event.errorOccurred: print("input: ErrorOccurred: \(aStream.streamError?.localizedDescription)") break case Stream.Event.openCompleted: print("input: OpenCompleted") break case Stream.Event.hasBytesAvailable: print("input: HasBytesAvailable") break default: break } } else { print("unkNown stuff happened") } }}解决方法 经过大量的试验和错误后,我终于意识到stream()函数不起作用只是因为这个函数的签名不正确/过时了.
这是我正在使用的:
func stream(aStream:Stream,handleEvent eventCode:Stream.Event)
但它真的应该是:
func stream(_ aStream:Stream,handle eventCode:Stream.Event)
这可能是从以前的Swift版本到Swift 3的语法转换.XCode编译器通常会检测过时的函数/语法,但遗憾的是没有捕获到这个.
希望我的回答可以帮助那些仍然遭受这个问题的人.
总结以上是内存溢出为你收集整理的ios – Swift中的非响应流委托全部内容,希望文章能够帮你解决ios – Swift中的非响应流委托所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)