| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
东半球最高效的 Protocol<=>Service 中间件,解决中间件的占用内存问题。
完善的中间件组件化示例工程
蘑菇街路线
优点:不需要注册和内存占用 ✅
缺点:编译阶段无法发现潜在BUG,必须遵守命名规则 🙅♂️
优点:接口与实现分离,编译阶段就能发现问题 ✅
缺点:需要注册和内存占用。
基于Protocol-Class方案
优点:同上Protocol-Class方案,但移除了注册逻辑,解决占用内存问题及Protocol对应ServiceClass存在性安全校验。
Map ✅
Cache ✅
安全模式
对外业务能力如果未实现,运行期调用会触发断言处,便于发现问题 ✅
部分缺点同上Protocol-Class
ProtocolServiceKit is available through cocoapods. To install it, simply add the following line to your Podfile:
// OC项目建议参考下行
pod 'ProtocolServiceKit',"~>2.2.1" # Default is ObjC
// Swift项目建议参考下行
pod 'ProtocolServiceKit/Swift',"~>2.2.1"
// deprecate
pod 'ProtocolServiceManger',"~>1.0.0"To run the example/SwiftExample project, clone the repo, and run pod install from the Example directory first.
为了方便理解,AccountBusiness和PlayBusiness 已部署为远端示例组件,仅暴露Protocol文件
- (Class)serviceClassWithProtocol:(Protocol *)aProtocol;
- (Class)serviceClassWithCachedProtocol:(Protocol *)cachedProtocol;
- (void)configProtocolServiceMapsWithDic:(NSDictionary < NSString * ,NSString *> *)mapDics;
// VIP和播放业务复杂后,只公开Protocol文件决定业务对外能力
// ServiceWithCachedProtocol 缓存使用
Class <LFLVipProtocol> vipService = ServiceWithProtocol(LFLVipProtocol);
// 不直接使用对应账户类 [LFLAccountTool isUserVipStatus];
BOOL isVip = [vipService isCurrentUserVipStatus];
if (vipService && isVip) {
[ServiceWithCachedProtocol(LFLPlayProtocol) playMiniVideo];
} else {
NSLog(@"Error:LFLVipProtocol notfound service Class");
}
/// Default Value NO 【setting YES,ignore All Error Type 】
@property (nonatomic,assign)BOOL ignoreSafeMode;
recommended convention
XXXService
XXXProtocol
项目已存在或者想自由风格命名:Map解决方案
NSDictionary *mapDic = @{
@"LFLUnRuleProtocol":@"LFLTestRuleIMP"
};
[[ProService sharedManger] configProtocolServiceMapsWithDic:mapDic];
ProtocolServiceKit.ProService
Swift版本有代码提示!
import ProtocolServiceKit.ProService
func ProtocolServiceNormalDemo() {
// 1.1 use
let normalService : AnyClass = ProtocolService.serviceClass(aProtocol: SwiftNormalProtocol.self)
// 1.2 Xcode can tip functions
normalService.normalFunction()
// 1.3 cache Service Class
let normalCacheServiceDemo : AnyClass = ProtocolService.serviceCacheClass(aProtocol: SwiftNormalProtocol.self)
normalCacheServiceDemo.normalFunction()
// 2.0 recommend most use Example
let normalCacheService : AnyClass = ProtocolService.serviceCacheClass(aProtocol: SwiftNormalProtocol.self)
normalCacheService.normalFunction()
}
func ProtocolServiceMapDemo() {
ProtocolService.configProtocolServiceMaps(mapDic: ["MapExampleProtocol":"MapUnRuleClass"], nameSpace: "SwiftExample")
let mapCacheService : AnyClass = ProtocolService.serviceCacheClass(aProtocol: MapExampleProtocol.self)
mapCacheService.MapExampleFunction()
}一般不建议使用此版本 [ branch Function]
// OC项目建议参考下行 pod 'ProtocolServiceKit', :git => 'https://github.com/DevDragonLi/ProtocolServiceKit.git', :branch => 'tipFunction' # Default is ObjC // Swift项目建议参考下行 pod 'ProtocolServiceKit/Swift', :git => 'https://github.com/DevDragonLi/ProtocolServiceKit.git', :branch => 'tipFunction'
DevdragonLi, dragonLi_52171@163.com
ProtocolServiceKit is available under the MIT license. See the LICENSE file for more info.
| Back | FazBrowse Home | New Git URL |