AppLord 1.2.1

AppLord 1.2.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2017年1月

NianJi维护。



AppLord 1.2.1

  • fengnianji

ios应用的模块和服务管理

添加到您的项目

cocoapods管理,使用

pod    'AppLord'

模块

什么是模块?每个业务或任务都可以是模块。

哪些模块初始化?在应用启动时或之后启动应用

如何实现?

首先,创建类

#import <AppLord/AppLord.h>
@interface MyModule : NSObject <ALModule>
@end

然后,像这样实现

@AppLordModule(MyModule) // Annotation for regist the module, required
@implementation MyModule

// module object init
- (void)moduleDidInit:(ALContext *)context
{
    // do some init thing
}

@end

服务

我们可以在模块内部从其他模块接收事件,但这并不总是满足需求。我们不能通知回发送者。因此,我们提供另一种在模块之间传输事件的方法:服务

如何使用?

定义自定义服务

@protocol MyService <ALService>

- (void)doSomething;

@end

实现它

@interface MyServiceImpl : NSObject <MyService>

@end

@AppLordService(MyService, MyServiceImpl) // regist MyService's Impl class: MyServiceImpl
@implementation MyServiceImpl

- (void)doSomething
{

}

// optional
+ (BOOL)globalVisible
{
    // if return YES, service will be always in the memory
}

@end

如何获取服务实例?

id<MyService> service = [[ALContext sharedContext] findServiceByName:@"MyService"];
// or
id<MyService> service = [[ALContext sharedContext] findService:@protocol(MyService)];