Snakit
更新了Xcode 9 以后,Snapkit就出了一些问题,报了10几个error。
去Github看了以后,作者给出了[NOTICE] Xcode 9 Compatibility with CocoaPods
Currently Cocoapods is not able to correctly mix Swift 3.2 and Swift 4.0 pods. SnapKit 4.0.0 is only compatible with Swift 4.0.0, if you have integration issues use SnapKit 3.2.0 as there is no functional difference between the two.
In a future release of SnapKit 4.x.0 we may bring compatibility with Swift 3.2.0 if Cocoapods continues to have issues.
大致意思是说cocoapods不能同时兼容Swift 3.2和Swift 4.0,若使用Swift 3.2就使用Snapkit 3.2.0,若使用Swift 4.0就使用Snapkit 4.0.0,这样就可以正常使用了。
Swift 4.0
@objc
Swift 4.0 需要把project和target的Swift 3.0 @objc Inference设置为Default。如图:
当使用OC相关的方法时,就要自己添加@objc,并且,如果使用KVC,所有的属性前面都要加@objc
subString
Swift 4.0弃用了subString,采用String.index来获取索引,然后使用范围来获取子串。例如:
/**
* String[]的方式获取的子串的类型为String.Subsequence,若要使用,
需要转换为String
* index方法有index(after),index(of),index(before)
* ...表示直到末尾
* ..<表示不包括最后一个字符
*/
let query = "code=12345678"
// 获取=后面的字符的索引
let start = query.index(after: query.index(of: "=")!)
// 从start索引开始一直到结束
let code = query[start...]
// code的结果为12345678
以上是我更新遇到的一些问题