A.一个workspace多个project
步骤:
1.创建一个XCWorkspace.xcworkspace
2.在XCWorkspace文件夹下创建多个项目工程 例:Project1 Project2
3.打开XCWorkspace.xcworkspace,添加project到xcworkspace
4.创建Podfile文件,编写对应的project引入的第三方库,公用的统一pod
5.pod install
1.创建一个XCWorkspace.xcworkspace

2.在XCWorkspace文件夹下创建多个项目工程 例:Project1 Project2

3.打开XCWorkspace.xcworkspace,添加project到xcworkspace



4.创建Podfile文件,编写对应的project引入的第三方库,公用的统一pod
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
workspace 'XCWorkspace.xcworkspace'
project 'Project1/Project1.xcodeproj'
project 'Project2/Project2.xcodeproj'
abstract_target 'CommonPods' do
#公用pods
use_frameworks!
pod 'SnapKit'
#project分别处理
target 'Project1' do
platform :ios, '9.0'
project 'Project1/Project1.xcodeproj'
end
target 'Project2' do
platform :ios, '11.0'
project 'Project2/Project2.xcodeproj'
end
end
5.pod install 之后多个同的project都引入了第三方库, 一个workspace多个project配置就全部完成.

B.一个project多个target
步骤:
1.添加target:duplicate一个target,同时也会生成一个Project1 copy-Info文件. (duplicate:与原target共用一份代码,可单独设置的编译参数、bundleid、 应用名、Icon等信息。一份代码 多个版本。)
2.修改target scheme Info.plist名称和Info.plist文件路径
3.设置预处理宏,区分不同的target版本。
4.添加target判断
1.添加target


2.修改target scheme Info.plist名称和Info.plist文件路径




3.设置预处理宏,区分不同的target版本。
Swift ,编译器不再支持预处理指令了,这里设置和OC有区别,定义需要添加"-D"。参考使用 Xcode 的 Target 区分开发和生产环境


4.添加target判断


网友评论