First, the SWIFT project by practice, the online method can not be successful, and then think about the definition of the debug macro, the actual measurement is effective, the way is as follows: NOTE: The SWIFT flags can not be folded after double-click Set-dtarget4appstore, This automatically clears the previously generated or defined macro definition
#if target4appstore self.view.backgroundColor = uicolor.yellow//effect when you run AppStore target, you can see the background image yellow with the interface debugging tool. else Self.view.backgroundColor = kbgcolor#endif
Second, the OC Project build setting search macro, in the preprocessor macros expanded state, the new copy of the target's debug and release under the macro definition.
viewcontroller.m// multargetstest//// Created by myl on 2017/4/12.// Copyright 2017 Huatu. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void ) Viewdidload { [super viewdidload]; #if is_macro version//macao, Xcode bug: Text highlighting does not change with switching scheme, but it is right to run. #if DEBUG self.view.backgroundColor = [Uicolor bluecolor]; #else self.view.backgroundColor = [Uicolor browncolor]; #endif #elif is_beijing//Beijing version #if DEBUG self.view.backgroundColor = [Uicolor cyancolor]; #else self.view.backgroundColor = [Uicolor blackcolor]; #endif #elif is_tianjing//Tianjin Edition, has not copied the target, will not go this #if DEBUG self.view.backgroundColor = [Uicolor Cyancolor]; #else self.view.backgroundColor = [Uicolor blackcolor]; #endif #else//Canton Edition #if DEBUG self.view.backgroundColor = [Uicolor redcolor]; #else self.view.backgroundColor = [Uicolor orangecolor]; #endif #endif } @end
The above code has been actually tested and is completely correct.
Summary: How multiple target in Swift, OC language is differentiated in code