Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode多目标--#ifdef';它跑过去了_Xcode_Conditional Compilation_Targets - Fatal编程技术网

Xcode多目标--#ifdef';它跑过去了

Xcode多目标--#ifdef';它跑过去了,xcode,conditional-compilation,targets,Xcode,Conditional Compilation,Targets,我有一个Xcode项目,有七个目标,对应于七个iPhone应用程序。这个数字可能会增加。许多目标使用许多相同的类 我复制了下面的部分应用程序代理。为了这篇文章的目的,我将target1更名为target7。我已经设置了相应的宏mTarget1到mTarget7。此外,我还有诸如mTarget12之类的宏,它是为目标1和2定义的 应用程序委托中的ifdef正在快速累积。为了说明这个问题,我在下面展示了app委托的一些部分 从好的方面看,这种积累似乎是加性的——它们并没有成倍增长,至少现在还没有。另

我有一个Xcode项目,有七个目标,对应于七个iPhone应用程序。这个数字可能会增加。许多目标使用许多相同的类

我复制了下面的部分应用程序代理。为了这篇文章的目的,我将target1更名为target7。我已经设置了相应的宏mTarget1到mTarget7。此外,我还有诸如mTarget12之类的宏,它是为目标1和2定义的

应用程序委托中的ifdef正在快速累积。为了说明这个问题,我在下面展示了app委托的一些部分

从好的方面看,这种积累似乎是加性的——它们并没有成倍增长,至少现在还没有。另一个好的方面是,除应用程序委托之外的文件中的#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

在某些情况下,实际创建不同版本的implementation.m文件可能是有意义的,甚至可能每个目标创建一个。实际上,您可以将后缀附加到basename,如myDelegate\u mTarget34.m等。。。或者将每个同名文件放在以目标命名的子文件夹中。然后将所有实现文件添加到项目中,并将其分配给一个目标(右键单击>信息>目标)

在某些情况下,实际创建不同版本的实现.m文件可能是有意义的,甚至每个目标一个。实际上,您可以将后缀附加到basename,如myDelegate\u mTarget34.m等。。。或者将每个同名文件放在以目标命名的子文件夹中。然后将所有实现文件添加到项目中,并将其分配给一个目标(右键单击>信息>目标)