У меня есть проект Xcode с семью целями, соответствующий семи iPhone-приложениям. Это число может увеличиться. Многие цели используют много одинаковых классов.Xcode несколько целей - # ifdef работает над
Я воспроизвел части делегата приложения ниже. Для целей этого поста я переименовал целевые объекты target1 через target7. У меня установлены соответствующие макросы mTarget1 через mTarget7. Кроме того, у меня есть макросы, такие как mTarget12, которые определены для целей 1 и 2.
Команда ifdef в делегате приложения быстро накапливается. Чтобы проиллюстрировать проблему, я показал часть делегата приложения ниже.
С яркой стороны накопление, похоже, является аддитивным - они не умножаются, по крайней мере, еще не достигнуты. Также на яркой стороне # ifdef в файлах, отличных от делегата приложения, не так уж плох.
На не очень яркой стороне в делегате приложения много накоплений.
Мне интересно, есть ли лучший способ организовать это. Я должен добавить, что я не думаю, что отдельные проекты Xcode являются опцией - это будет хуже, чем у меня сейчас.
#ifndef mTarget34
// an import
#endif
#ifdef mTarget56
// an import
#endif
#ifdef mTarget7
// an import
#endif
#ifdef mTarget12
// a bunch of imports
#endif
#ifdef mTarget2
// an import
#endif
#ifdef mTarget4
// an import
#endif
@implementation xxxAppDelegate
@synthesize window;
#ifdef mTarget1
// synthesize a member
#endif
#ifdef mTarget34
// synthesize a member
#endif
#ifdef mTarget5
// synthesize four members
#endif
- (void)dealloc {
[window release];
[super dealloc];
#ifdef mTarget1
// release a member
#endif
#ifdef mTarget34
// release a member
#endif
}
- (void) logMacroes {
// a bunch more ifdef's here because it is helpful to NSLog my macroes when the program starts.
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[self logMacroes];
#ifdef mTarget1
//start analytics
#endif
#ifndef mTarget7
//start up the sound
#endif
#ifndef mTarget34
# ifndef mTarget7
// load the data model
# endif
#endif
#ifdef mTarget12
// create a bunch of tabs for the tab bar
#endif
#ifdef mTarget2
// start analytics
// create a view controller that will eventually go into the tab bar.
#endif
#ifdef mTarget12
NSMutableArray *vc = [[NSMutableArray alloc]initWithObjects:
// a bunch of objects
# ifdef mTarget2
// another object . . . we are still inside the initWithObjects statement here.
# endif
# ifdef mTarget1
// another object
# endif
nil]; // initWithObjects finally done.
//release a bunch of stuff
# ifdef mTarget2
//another release
# endif
// use the array we just created to create a tab bar controller.
// Add the tab bar controller to the window
#endif
#ifdef mTarget34
// hide the status bar
// create a navigation controller and add it to the window.
#endif
#ifdef mTarget56
//Hide the status bar. Create a view controller and add it to the window.
#endif
#ifdef mTarget7
// create a view controller and add it to the window.
#endif
[window makeKeyAndVisible];
}
#ifndef mTarget34
# ifndef mTarget7
- (void)applicationDidEnterBackground:(UIApplication *)application {
// save the model
}
- (void) applicationWillTerminate: (UIApplication *) application {
// save the model
}
# endif
#endif