iOS构建多Target可以用来做马甲包,具有使用性。以下是构建新的Target步骤:
Step 1: 拷贝一个新的Target。
右键选中现有的Target,点击"Duplicate"。

Step 2: 拷贝一个新的Target的名字和对应info.plist名字
两个都是选中,直接“回车键”,进行更改。

Step 3: 修改Sechem名字。



直接回车选中,修改名字后,点击"Close".
Step 4: 修改info.plist位置。
在项目根目录下建对应的文件夹,来存放以后不同Target不同的文件。

将现有的info.plist文件移到对应文件下。

此时要注意:仅选择对应的文件即可。

Step 5: 修改info.plist引用。


此时要注意:这个时候我们去编译原来的Target时会报错:

选中原有的Target,删除多余的引用:

Step 6: 添加系统的宏命令,通过宏区分不同Target。


使用方法:可以在代码里直接通过TargetType来区分不同Target
if (TargetType==1) {
NSLog(@"原来的target");
} else if(TargetType==2){
NSLog(@"新建的target");
}
Step 7: 如果有使用CocoaPods,修改Podfile文件
def common_Pods
pod 'MJRefresh'
pod 'ReactiveCocoa’,'~> 2.4.7’
pod 'Masonry’,'~> 1.1.0’
pod 'YYCache'
pod 'FLEX’
end
target 'KnowledgeSummaryOfObjectC' do
common_Pods
end
target 'TargetOne' do
common_Pods
end
网友评论