Summary: How multiple target in Swift, OC language is differentiated in code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.