美文网首页iOS Tips
iOS项目从 Swift3.2 升级到 Swift4.0 报错解

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

作者: 猴子的救兵520 | 来源:发表于2017-11-08 16:14 被阅读315次

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

buildSetting_Swift3objcInterface@2x.png

相关文章

网友评论

    本文标题:iOS项目从 Swift3.2 升级到 Swift4.0 报错解

    本文链接:https://www.haomeiwen.com/subject/bubemxtx.html