ios objection

给大家介绍个不错的团队开发模块化工具objection

1. setup<这里我只介绍ios相关>

rake artifact:ios
cp -R build/Release-iphoneuniversal/Objection-iOS.framework ${DEST_DIR}
In XCode -> Project Icon -> Your Target -> Build Phases -> Link Binary With Libraries -> Add (+) -> Add Other
Add -ObjC and -all_load to Other Link Flags in your project

这里只需要用到 Release-iphoneuniversal->Objection-iOS.framework 即可

 

2.结构图

 

3. 具体使用、功能

 1 //初始化
 2 JSObjectionInjector *injector = [JSObjection defaultInjector];  [1] 
 3 injector = injector ? : [JSObjection createInjector];     [2] 
 4 injector = [injector withModules:[[MyModel alloc] init]nil];[3]  
 5     
 6 //获取JSObjectionInjector对象
 7 JSObjectionInjector *injector = [JSObjection defaultInjector]; // [4]
 8 MasterViewController <ViewControllerAProtocol> *vc = [injector getObject:@protocol(ViewControllerAProtocol)]; // [5]
 9 vc.backgroundColor = [UIColor lightGrayColor]; // [6]
10 UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
11 self.window.rootViewController = nc;
12 [self.window makeKeyWindow];
[1] 获取默认的injector,这个injector已经注册过ViewControllerAProtocol了。
[2] 获取ViewControllerAProtocol对应的Object。
[3] 拿到VC后,设置它的某些属性,比如这里的backgroundColor,因为在ViewControllerAProtocol里有定义这个属性
 
[4] 获取默认的 injector
[5] 如果默认的 injector 不存在,就新建一个
[6] 往这个 injector 里注册我们的 Module  设置该 injector 为默认的 injector
这段代码可以直接放到 + (void)load里执行,这样就可以避免在AppDelegate里import各种Module。

 

4.具体项目效果:

各个Section可以由不同的人负责,然后串到一起就行,也能一定程度地避免MVC(Mess View Controller)的出现。

 

 

posted on 2014-04-21 18:04  tinkl  阅读(1056)  评论(1编辑  收藏  举报

导航