美文网首页
iOS解耦方案

iOS解耦方案

作者: 纳美克星人 | 来源:发表于2019-03-21 21:13 被阅读0次

解耦方案是针对AppDelegate,通过消息的转发、GCDMulticastDelegate代理的一对多模式来实现解耦。以下是核心代码:

消息转发:

+ (BOOL)resolveInstanceMethod:(SEL)sel{

    return NO;

}

- (id)forwardingTargetForSelector:(SEL)aSelector{

    if([selfrespondsToSelector:aSelector]) {

        return self;

    }

    return self.multicastDelegate;

}

添加delegate:

- (void)addImplementationArray:(NSArray *)targets

                         queue:(dispatch_queue_t)queue;

- (void)addImplementationQueueTarget:(id)target

                               queue:(dispatch_queue_t)queue

需要使用AppDelegate方法的类,需要实现UIApplicationDelegate协议。

https://github.com/PangDu/PDAppDelegate

相关文章

网友评论

      本文标题:iOS解耦方案

      本文链接:https://www.haomeiwen.com/subject/gnrhvqtx.html