Xcode 7.1 beta: Content Of File Error

后端 未结 1 369
执笔经年
执笔经年 2021-01-28 04:35

I had just finished the final touches to my swift app. But after upgrading to Beta 7 its giving me errors for the \'ContentOfFile\' String. can anyone help me understand how I c

相关标签:
1条回答
  • 2021-01-28 04:57

    You need to implement do try catch error handling. Try like this:

    edit/update:

    Swift 3 or later

    if let fileURL = Bundle.main.url(forResource: "Chapters", withExtension: "txt") {
        do {
            let string = try String(contentsOf: fileURL, encoding: .utf8)
            var chapters = string.components(separatedBy: "@")
            chapters.removeFirst()
        } catch {
            print(error)
        }
    }
    
    0 讨论(0)
提交回复
热议问题