Swift中的免费电话桥接和指针访问

Swift中的免费电话桥接和指针访问,第1张

Swift中的免费电话桥接和指针访问

我可以使用它,这是我的代码:确保在某处保留连接类的引用:-)

class Connection : NSObject, NSStreamDelegate {    let serverAddress: CFString = "127.0.0.1"    let serverPort: UInt32 = 8443    private var inputStream: NSInputStream!    private var outputStream: NSOutputStream!    func connect() {        println("connecting...")        var readStream:  Unmanaged<CFReadStream>?        var writeStream: Unmanaged<CFWriteStream>?        CFStreamCreatePairWithSocketToHost(nil, self.serverAddress, self.serverPort, &readStream, &writeStream)        // documentation suggests readStream and writeStream can be assumed to        // be non-nil. If you believe otherwise, you can test if either is nil        // and implement whatever error-handling you wish.        self.inputStream = readStream!.takeRetainedValue()        self.outputStream = writeStream!.takeRetainedValue()        self.inputStream.delegate = self        self.outputStream.delegate = self        self.inputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)        self.outputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)        self.inputStream.open()        self.outputStream.open()    }    func stream(stream: NSStream, handleEvent eventCode: NSStreamEvent) {        println("stream event")    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5622502.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存