加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 如何从Xcode中的相同共享代码创建多个应用程序?

发布时间:2020-12-15 01:58:43 所属栏目:百科 来源:网络整理
导读:我正在开发共享95%相同代码和视图的2个不同的应用程序。使用Xcode最好的方法是什么? 解决方法 使用目标。这正是他们的意思。 Learn more about the concept of targets here。 通常情况下,大多数项目都有一个Target,它对应于一个产品/应用程序。如果您定
我正在开发共享95%相同代码和视图的2个不同的应用程序。使用Xcode最好的方法是什么?

解决方法

使用目标。这正是他们的意思。

Learn more about the concept of targets here。

通常情况下,大多数项目都有一个Target,它对应于一个产品/应用程序。如果您定义多个目标,您可以:

>包括一些源代码文件(或可能全部)在两个目标,一些在一个目标和一些在另一个目标
>您可以使用Build Settings进行编辑,使用不同的设置编译两个目标。

例如,您可以为一个目标和其他宏定义预编译器宏(假设目标“PremiumVersion”中为OTHER_C_FLAGS = -DPREMIUM)和OTHER_C_FLAGS = -DLITE来定义“LiteVersion”目标中的LITE宏),然后包括类似的代码在你的来源:

-(IBAction)commonCodeToBothTargetsHere
{
   ...
}

-(void)doStuffOnlyAvailableForPremiumVersion
{
#if PREMIUM
   // This code will only be compiled if the PREMIUM macro is defined
   // namely only when you compile the "PremiumVersion" target
   .... // do real stuff
#else
   // This code will only be compiled if the PREMIUM macro is NOT defined
   // namely when you compile the "LiteVersion" target

   [[[[UIAlertView alloc] initWithTitle:@"Only for premium" 
       message:@"Sorry,this feature is reserved for premium users. Go buy the premium version on the AppStore!"
       delegate:self
       cancelButtonTitle:@"Doh!"
       otherButtonTitles:@"Go buy it!",nil]
   autorelease] show];
#endif
}

-(void)otherCommonCodeToBothTargetsHere
{
   ...
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读