socket - ios 代理模式如何转换成顺序执行的流程?
迷茫
迷茫 2017-04-18 09:24:57
0
3
530
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
Peter_Zhu

Your question is really abstract
1. Receiving or sending data is an independent function, assuming it is sendRead, separate it from the business. In this way, when receiving data, just receive the data. When the data reaches the standard you want, call back from the sendRead module.
readFromSocket(buffer)
This method can be transformed into a style with a closure (block) callback:

func readFromSocket(data:NSData,completeHander:(receivedData:NSData?)-> Void){
    //接收数据的事

    //在某个时机调用回调,应该不是当前这个方法里,接收数据应该都是异步的吧
    completeHander(receivedData: xxx)
}

When your business execution reaches a certain stage and you need certain data, call this and then process it in the callback. At this time, the callback only needs to handle the logic of this stage. Although this still cannot make sequential calls, because receiving data cannot be completed at once, and it must wait for the data recipient to proactively notify. 2. I see that you have to make multiple status judgments in handleData. Is this business running with multiple threads at the same time? If not, it would be simpler, because the APP is currently in one state, and you only need to collect the data of a single state first and then throw it to the business code for processing. Otherwise, the business logic must be separated, and the read operations must also be separated.

左手右手慢动作

Why so many spelling mistakes?

小葫芦

ReactiveCocoas or RxSwift

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template