У меня есть проект Xcode с семью целями, соответствующими семи приложениям для iPhone.Это число может увеличиться.Многие цели используют много одинаковых классов.
Я воспроизвел части делегата приложения ниже.Для целей этого поста я переименовал цели 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