HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了小结:Swift、OC语言中多target在代码中如何区分大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
一、对swift工程
经实践,网上的方法都无法成功,后来思DEBUG宏定义方式,经实测有效,方式如下:
注意:不能把swift flags 小三角折叠后双击设置-DTarget4AppStore,这样会自动清空之前生成或定义的宏定义

小结:Swift、OC语言中多target在代码中如何区分

小结:Swift、OC语言中多target在代码中如何区分

 
@H_944_21@
 #if Target4AppStore
        self.view.BACkgroundColor = UIColor.yellow//效果在运行appstore target时,通过界面调试工具可看到背景图为黄色
  #else
        self.view.BACkgroundColor = kBGColor
#endif

 

 
 
二、对OC工程
build setTing中搜索 macro,在preprocessor Macros展开状态下,对新复制出的target的debug和release下都加上宏定义。
 

小结:Swift、OC语言中多target在代码中如何区分

小结:Swift、OC语言中多target在代码中如何区分

@H_944_21@
//
//  ViewController.m
//  mulTargetsTest
//
//  Created by myl on 2017/4/12.
//  Copyright © 2017年. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  
  
#if IS_MACRO //macao 版,Xcode缺陷:文本高亮状态不会随着切换scheR_732_11845@e变化,但是运行起来是对的。
  #if DEBUG
    self.view.BACkgroundColor = [UIColor blueColor];
  #else
    self.view.BACkgroundColor = [UIColor brownColor];
  #endif
#elif  IS_BEIJING//北京版
  #if DEBUG
    self.view.BACkgroundColor = [UIColor cyanColor];
  #else
    self.view.BACkgroundColor = [UIColor blackColor];
  #endif
  
#elif  IS_TIANJING//天津版,还未复制出target,不会走这
  #if DEBUG
    self.view.BACkgroundColor = [UIColor cyanColor];
  #else
    self.view.BACkgroundColor = [UIColor blackColor];
  #endif
#else//广州版
  #if DEBUG
  self.view.BACkgroundColor = [UIColor redColor];
  #else
   self.view.BACkgroundColor = [UIColor orangeColor];
  #endif
#endif
  
}

@end

 

以上代码已经过实际测试,完全正确。
 
 
 

大佬总结

以上是大佬教程为你收集整理的小结:Swift、OC语言中多target在代码中如何区分全部内容,希望文章能够帮你解决小结:Swift、OC语言中多target在代码中如何区分所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:
猜你在找的HTML5相关文章