Ios 台风-儿童计划
在一个遗留应用程序中,我将逐步引入Typhone,如果我想从一个本身不是从Typhone实例化的类实例化一个Typhone实例,我可以在我的AppDelegate中放置以下内容:Ios 台风-儿童计划,ios,typhoon,Ios,Typhoon,在一个遗留应用程序中,我将逐步引入Typhone,如果我想从一个本身不是从Typhone实例化的类实例化一个Typhone实例,我可以在我的AppDelegate中放置以下内容: [self.assembly makeDefault]; 以及我的程序集中AppDelegate的定义: - (AppDelegate *)appDelegate { return [TyphoonDefinition withClass:[PFAppDelegate class] config
[self.assembly makeDefault];
以及我的程序集中AppDelegate的定义:
- (AppDelegate *)appDelegate
{
return [TyphoonDefinition withClass:[PFAppDelegate class]
configuration:^(TyphoonDefinition *definition)
{
[definition injectProperty:@selector(assembly) with:self];
}];
}
MyAssembly* assembly = [MyAssembly defaultAssembly];
在其他地方,我可以执行以下操作以获取程序集的实例:
- (AppDelegate *)appDelegate
{
return [TyphoonDefinition withClass:[PFAppDelegate class]
configuration:^(TyphoonDefinition *definition)
{
[definition injectProperty:@selector(assembly) with:self];
}];
}
MyAssembly* assembly = [MyAssembly defaultAssembly];
这是可以的,但假设我的应用程序由以下部分组成:
- 包含各种子项目的主项目
- 主项目对Typhone具有pod依赖性,assembly在这里编写,并且具有要注入到其子项目中的对象的定义
MyAssembly*assembly=[MyAssembly defaultAssembly];
在这种情况下,我应该如何处理?在典型的台风应用程序中,您将有:
- TyphonComponentFactory的一个实例
- 将几个程序集分离到逻辑体系结构层中。这些组件可以相互引用李>
TyphonComponentFactory
中
一旦应用程序启动,程序集本身基本上被丢弃,但您的程序集接口仍然可以充当TyphonComponentFactory
-来自程序集接口的方法调用使用Objective-C转发并转换为[factory componentForKey]
因此
- 您可以将
强制转换到任何程序集接口,它都可以工作李>typhoncomponentfactory
- 您可以将任何程序集接口强制转换为子程序集接口,它将正常工作李>
- 您可以将程序集接口强制转换为
李>typhoncomponentfactory
typhoncomponentfactory
实例。在一个非常复杂的应用程序中,你可能会有更多,一个用于引擎或库,一个用于主应用程序,而这些部分不需要知道其他部分是由台风支持的。但是,如果您有一组相互引用的程序集,并且在启动时一起实例化,形成一个typhoncomponentfactory
,那么您可以在它们之间强制转换。只需使用:
MyChildAssembly *childAssembly = (MyChildAssembly) parentAssembly;
我不确定你是否理解我的问题。我的子项目没有依赖项Typhone,因此它们无法导入Typhone,因此我无法在子项目中生成程序集。更重要的是,子项目不知道主项目要求主装配。啊,我明白了。是的,我误解了你的问题。请不要理会那个答案。