阅读 1339

XCode12前版本编译Swift5.3新语法的错误

由于Swift语法的不断更新迭代,不同版本XCode编译器在编译swift文件,做语法检查的时候,检测到该语法不支持。爆出这样的错误

CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler

what's problem ?

The following build commands failed:CompileSwift normal armv7 
xxx.swiftCompileSwiftSources normal arm64 
com.apple.xcode.tools.swift.compilerCompileSwift normal arm64 xxx.swift
复制代码

How happen ?

xxx.swift:24:10: error: consecutive statements on a line must be separated by ';'} 
completion: { _ in^;xxx.swift:24:21: error: expected expression} 
completion: { _ in^xxx.swift:24:11: error: use of unresolved identifier 'completion'} 
completion: { _ in^~~~~~~~~~xxx.swift:24:23: 
error: unable to infer closure type in the current context} 
completion: { _ in^~~~~~xxx.swift:24:23: 
error: closure expression is unused} 
completion: { _ in
复制代码

How fix ?

// xcode12 and above
UIView.animate(withDuration: 0.3) {
    // animation actions
} completion: { _ in
    // some finished actions
}

// below xcode12
UIView.animate(withDuration: 0.3, animations: {
    // animation actions
}, completion: { _ in
    // some finished actions
})
复制代码

Why ?

目前Swift的稳定版本是5.4

docs.swift.org/swift-book/…

XCode新建项目的build-setting中Swift Language Version 设置为 Swift5

近期在项目开发中使用到了swift,在本地可以正常编译运行项目,但是在jenkins打包的时候抛出如下错误。

分析总结这个问题,避免后面的同学被同一个问题困扰。

参考XCode更新文档

developer.apple.com/xcode/whats…

发现从XCode12以后才开始引入Swift5.3及以上版本

Swift5.3更新部分

文章分类
iOS
文章标签