我有一个带有多个XML文件的Typhoon1.x实现。我有多个应用依赖于一个公共的库。我有一个默认的xml文件,其中包含针对不同应用程序的“默认”实现的公用库。然后,每个应用程序都有自己的xml文件,该文件能够覆盖为键定义的对象类型。此覆盖是通过自定义工厂完成的。
库xml:
<!-- DEFAULT MENU -->
<component class="my_menu" key="menu_default"/>应用1 xml:
<!-- APP 1 MENU -->
<component class="my_app1_menu" key="menu"/>应用2 xml:
<!-- APP 2 MENU -->
<!-- None - use default -->然后,我的自定义工厂接受一个键值,尝试访问Typhoon中的" key“。如果为'nil',则再次尝试访问:"key“+ "_default”。
我的工厂方法:
- (id) componentForKey:(NSString *)key
{
TyphoonComponentFactory *factory = [TyphoonComponentFactory defaultFactory];
@try {
id obj = [factory componentForKey:key];
if (obj) {
return obj;
}
}
@catch (NSException *exception) {
DLog(@"Couldn't find %@", key);
DLog(@"Nope");
}
// Try Default
@try {
key = [NSString stringWithFormat:@"%@_default", key];
id obj = [factory componentForKey:key];
if (obj) {
return obj;
}
}
@catch (NSException *exception) {
DLog(@"Couldn't find %@", key);
DLog(@"No Default");
DLog(@"Exception: %@", exception);
}
return nil;
}因为Typhoon的XML实现在2.x版本中停止了。我想超越1.x和我们当前的XML文件。然而,我很难找到一个可以工作的实现。
这一点很重要的原因是,每个应用程序本质上都是由库行为定义的基础应用程序的自定义皮肤。随着新特性的添加,该库的typhoon将填充"_default“定义。然后,当我们使用最新版本的库启动每个应用程序时,至少我们定义了一个基本实现,这样我们就不必到处跟踪'nil‘值。
发布于 2015-08-28 09:00:04
是的,不幸的是,从Typhoon2.x开始不支持XML。然而,您希望实现的功能得到了‘组装’风格的配置的良好支持。总而言之:
示例:
假设您有以下顶级程序集:
@interface MyAppAssembly : TyphoonAssembly
@property(nonatomic, strong, readonly) LibraryAssembly *library;
@end您可以按如下方式激活它:
MyAppAssembly *assembly = [[MyAppAssembly new]
activateWithCollaboratingAssemblies:[CustomizedLibraryAssembly new]];在启动时,Typhoon会说:
CustomizedLibraryAssembly will act in place of LibraryAssembly在CustomizedLibraryAssembly中,您可以覆盖任何您喜欢的定义。
感谢您成为Typhoon的早期使用者。如果您在移植到最新版本时需要帮助,请通过电子邮件发送,我们很乐意为您提供帮助。
发布于 2015-09-02 02:14:55
所以我想出了一个解决方案,我们几乎完全转移了,使用Typhoon 3.x。
@interface LibAssembly : TyphoonAssembly
@end
@implementation LibAssembly
- (id) menu {
return [TyphoonDefinition withClass:[MyMenu class]];
}
@end然后对于每个应用程序:
@interface AppAssembly : LibAssembly
@end
@implementation AppAssembly
- (id) menu {
return [TyphoonDefinition withClass:[AppMenu class]];
}
@end而我的工厂方法更改为:
- (id) componentForKey:(NSString *)key
{
// Check Init
if (!self.assembly) {
@throw @"Assembly not initialized properly - please call 'initWithAssemblerClass:' first";
}
SEL selector = NSSelectorFromString(key);
if ([self.assembly respondsToSelector:selector]) {
return [self.assembly performSelector:selector];
}
return nil;
}
+ (void) initWithAssemblerClass:(Class)assemblerClass
{
TyphoonAssembly *assembly = [assemblerClass new];
[assembly activate];
[MyFactory setAssembly: assembly];
}然后,我们只需向每个应用程序的委托添加一个初始化步骤:
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// INIT TYPHOON
[MyFactory initWithAssemblerClass:[AppAssembly class]];
...
}https://stackoverflow.com/questions/32258370
复制相似问题