Giter VIP home page Giter VIP logo

applord's Introduction

AppLord

module and service management of ios app

add to your project

management by cocoapods, use:

pod    'AppLord'

module

what is module? every business or task could be module.

when the module init? when app launch or after app launch

how to impl?

first, create class:

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

then, impl like this:

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

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

@end

service

we can receive events from other modules in a module, but it does not always meet the demand. we can't notify back to the sender. so we provide another way to transfer event between modules: service.

How to use?

Define your custom service

@protocol MyService <ALService>

- (void)doSomething;

@end

Impl it

@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

How to get the instance of service?

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

applord's People

Contributors

nianji avatar skyline75489 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

applord's Issues

lack files

the download zip lack of ALEvent.h and .m files

readModuleAndServiceRegistedInSection 注册service协议实现类有问题

  • (void)readModuleAndServiceRegistedInSection
    {
    NSArray<NSString *> *dataListInSection = AppLordReadConfigFromSection("AppLord");
    for (NSString *item in dataListInSection) {
    NSArray *components = [item componentsSeparatedByString:@":"];
    if (components.count >= 2) {
    NSString *type = components[0];
    if ([type isEqualToString:@"M"]) {
    NSString *modName = components[1];
    Class modCls = NSClassFromString(modName);
    if (modCls) {
    [self registerModule:modCls];
    }
    } else if ([type isEqualToString:@"S"] && components.count == 3) {
    NSString *serName = components[1];
    NSString *serImplName = components[1];
    Protocol *serPro = NSProtocolFromString(serName);
    Class serCls = NSClassFromString(serImplName);
    if (serPro && serCls) {
    [self registerService:serPro withImpl:serCls];
    }
    }
    }
    }

您好nianji,在使用您的框架的时候发现有个问题,是不是应该将NSString *serImplName = components[1] 改为NSString *serImplName = components[2], 就是这里应该是service 协议的实现类名。

- (void)registerService:(Protocol *)proto withImpl:(Class)implClass 方法里关于globalVisible是否实现判断

  • (void)registerService:(Protocol *)proto withImpl:(Class)implClass
    {
    NSParameterAssert(proto != nil);
    NSParameterAssert(implClass != nil);
    if (![implClass conformsToProtocol:proto]) {
    @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"%@ 服务不符合 %@ 协议", NSStringFromClass(implClass), NSStringFromProtocol(proto)] userInfo:nil];
    }
    if ([_servicesByName objectForKey:NSStringFromProtocol(proto)]) {
    @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"%@ 协议已经注册", NSStringFromProtocol(proto)] userInfo:nil];
    }
    // Register Protocol
    NSString *protoName = NSStringFromProtocol(proto);
    if (protoName) {
    if ([implClass resolveClassMethod:@selector(globalVisible)]) {
    BOOL isGlobal = [implClass globalVisible];
    if (isGlobal) {
    id service = [[implClass alloc] init];
    [_servicesByName setObject:service forKey:protoName];
    } else {
    [_serviceClassesByName setObject:implClass forKey:protoName];
    }
    } else {
    [_serviceClassesByName setObject:implClass forKey:protoName];
    }
    }
    }

nianji,您好,这个地方我验证如果自定义实现globalVisible方法时,不会走进这个条件中,我用if([implClass respondsToSelector:@selector(globalVisible)]) 是正常的,nianji也可以看看哈。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.