在Xcode 8.3中编译时的分段错误11

时间:2017-05-01 00:19:59

标签: swift xcode

当我尝试编译时,我在Xcode中遇到了“分段错误11”。这是我的代码:

import Foundation
import UIKit

class DataImportController {
    func startImport() {
        if let dataPath = Bundle.main.path(forResource: "stops", ofType: "csv") {
            do {
                let fileContents = try String(contentsOfFile: dataPath, encoding:.utf8)
                let contents = fileContents.components(separatedBy: CharacterSet.newLines)
            } catch  {
                print(error)
            }
        }
    }
}

这是邮件转储:

1.  While type-checking 'startImport' at /Users/Jaime/Developer/ETA/ETA/Model Controllers/DataImportController.swift:13:5
2.  While type-checking declaration 0x7fb185b34948 at /Users/Jaime/Developer/ETA/ETA/Model Controllers/DataImportController.swift:17:17
3.  While type-checking expression at [/Users/Jaime/Developer/ETA/ETA/Model Controllers/DataImportController.swift:17:32 - line:17:90] RangeText="fileContents.components(separatedBy: CharacterSet.newLines)"

代码有什么问题吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

表达式CharacterSet.newLines毫无意义。你的意思是CharacterSet.newlines ......?进行替换(或仅编写.newlines)将允许您的代码进行编译。