代码的优雅

2020-08-12  本文已影响0人  L63C

创建线程

static dispatch_queue_t user_handel_queue(){
    static dispatch_queue_t user_handel_queue_t ;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        user_handel_queue_t = dispatch_queue_create("user_handel_queue_t", DISPATCH_QUEUE_CONCURRENT);
    });
    return user_handel_queue_t;
}

判断代理或者协议

下面的方式,一个标志为只会占用一个二进制,并且不用每次使用代理都去判断是否实现协议那样冗长的代码。很棒吧

struct {
    unsigned int sendSDPFlag        :1;
    unsigned int sendCandidateFlag  :1;
}_delegateFlag;

- (void)setDelegate:(id<WebRTCHelperDelegate>)delegate{
    _delegate = delegate;
    _delegateFlag.sendSDPFlag = [delegate respondsToSelector:@selector(needSendSDPToPeer:offer:)];
    _delegateFlag.sendCandidateFlag = [delegate respondsToSelector:@selector(needSendCandidateToPeer:)];
}
 if(_delegateFlag.sendCandidateFlag){
        [self.delegate needSendCandidateToPeer:candidateStr];
    }
上一篇下一篇

猜你喜欢

热点阅读