Implement AsyncSocket callbacks in a swift class

后端 未结 1 1157
野性不改
野性不改 2021-01-16 09:55

I have a custom ViewController delegate class, which handles ui actions such as button clicked and display text in a text view.

Now I want to use AsyncSocket in the

相关标签:
1条回答
  • 2021-01-16 10:41
    // - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port;
    func socket(socket : GCDAsyncSocket, didConnectToHost host:String, port p:UInt16) 
    
    // - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag;      
    func socket(socket : GCDAsyncSocket, didReadData data:NSData, withTag tag:Int32) 
    

    Don't forget to make your swift class inherit from NSObject, otherwise the GCDAsyncSocket will fail to assign it as a delegate.

    Also, do not mark any parameters as var as in var didReadData data:NSData

    0 讨论(0)
提交回复
热议问题