关于Xcode8的坑爹pod配置

看这篇博客前请将Mac系统升级到最新版本

笔者前几天发现Xcode8新建的工程中一直出现这样一个错误:

“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

本人按照上面的提示尝试修改后,发现如果按照这个提示更改会直接改动你项目里问代码,导致我一直command+z恢复到最开始的状态。

发现按照其原来的提示不行,决定google一下。

原来是因为cocoapods的问题,你需要在先前的Podfile文件的结尾处添加几行:

1
2
3
4
5
6
7
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end

然后重新pod install 下就可以了,install之后打开相应的xcworkspace文件,在里面的set buildings中的一个叫做“Use Legacy Swift Language Version”的选项勾选NO。

这样那个错误应该没有了。

或者在Podfile的结尾处输入

1
2
3
4
5
6
7
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '2.3'
end
end
end

然后在相应位置改为YES。

笔者按照这个过程实践了一下,发现没有任何卵用。

于是继续google,发现是我的cocoapods版本太低,需要升级到1.1.0

于是在终端中输入

1
sudo gem install -n /usr/local/bin cocoapods --pre

但是又返回了另外一个错误

1
2
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj

于是本人又去google,发现是系统版本过低,于是升级为macOS。

最终,文章开头的错误消失了。