iOS项目从 Swift3.2 升级到 Swift4.0 报错解决

Swift3.2 --> Swift4.0 报错

  • Subscripts returning String were obsoleted in Swift 4; explicitly construct a String from subscripted result

下标返回子字符串的写法,在Swift4.0中被废弃了,需要显示的返回一个字符串。

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 调用 Swift4.0 报错

  • 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 设置为On

你可能感兴趣的:(iOS项目从 Swift3.2 升级到 Swift4.0 报错解决)