Swift3.2 --> Swift4.0 報(bào)錯(cuò)
- Subscripts returning String were obsoleted in Swift 4; explicitly construct a String from subscripted result
下標(biāo)返回子字符串的寫法,在Swift4.0中被廢棄了,需要顯示的返回一個(gè)字符串。
extension String {
func stringFromRange(from start: Int, to end:Int) -> String{
// Swift3.2的寫法 return self[self.index(self.startIndex, offsetBy: start)...self.index(self.startIndex, offsetBy: end)]
return String(self[self.index(self.startIndex, offsetBy: start)...self.index(self.startIndex, offsetBy: end)])
}
}
OC 調(diào)用 Swift4.0 報(bào)錯(cuò)
- Property 'xxxx' not found on object of type 'xxxx'
解決方法:在屬性前面加上 @objc 修飾符
- No visible @interface for 'xxxx' declares the selector 'xxxx'
解決方法:在方法前面加上 @objc 修飾符
偷懶的解決方法:BuildSetting 中 搜索 Swift 3 @objc interface 設(shè)置為On
buildSetting_Swift3objcInterface@2x.png