随着Xcode9 Swift4 的到来,一些小问题也接踵而至。许多优秀的Swift第三方框架还未来得及迎接Swift4的到来,它们还停留在swift3.x的状态,这个时候新建一个项目,使用cocoapods写上需要使用的第三方,一编译就是满屏红,如下图。
报错
所幸,苹果每次升级Xcode都会保留上个版本的swift,以防暴乱?~~
有两种解决方案 其本质都是控制编译时所使用的Swift版本
Pods -> Targets -> SnapKit -> Build Settings -> Swift language version option 选择 Swift 3.2。不推荐使用该方法,一个个点效率有些低~~
Pods
打开Podfile文件,添加并按需要修改下方代码来指定哪些第三方的Swift编译版本,接着来一次
pod install
最后再来一下编译就搞定了
post_install do |installer|
# 需要指定编译版本的第三方的名称
myTargets = ['ObjectMapper', 'SnapKit']
installer.pods_project.targets.each do |target|
if myTargets.include? target.name
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.2'
end
end
end
end
位置如图所示
Cocoapods
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有