ios 如何更合理的注入 protocol

App开发相关产品技术讨论,包括OEM App、App SDK等话题


Post Reply
zerozheng
Posts: 2

ThingSmartBizCore 目前提供了以下两个方法来注册服务:

Code: Select all

/**
 * Register a instance for service which can not be served by BizBundle itself
 * Each service can only register one instance or class at a time, whichever is the last
 *
 * @param service   service protocol
 * @param instance  instance which conform to the service protocol, strong reference
 *                  unregister if nil
 */
- (void)registerService:(Protocol *)service withInstance:(id)instance;

/**
 * Register a class for service which can not be served by BizBundle itself
 * Each service can only register one instance or class at a time, whichever is the last
 *
 *
 * @param service   service protocol
 * @param cls       class which conform to the service protocol, [cls new] to get instance
 *                  unregister if nil
 */
- (void)registerService:(Protocol *)service withClass:(Class)cls;

其中以instance的方法注册的服务不能通过 respondsToSelector 判断是否支持某个方法,通过class注册的服务可以。因此推荐使用class这种方式。


Tags:
OS App - 尼奥
Posts: 11

Re: ios 如何更合理的注入 protocol

registerService 方法目前只能注入“ UI 业务包中未实现的 Protocol ”,可以注入的 Protocol 一般是在对应 UI 业务包的文档中会有说明。

暂时还不支持针对“ UI 业务包中已实现的 Protocol ”替换单个 API 的诉求。

Post Reply