当我尝试编译时,我在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)"
代码有什么问题吗?
提前致谢。
答案 0 :(得分:0)
表达式CharacterSet.newLines
毫无意义。你的意思是CharacterSet.newlines
......?进行替换(或仅编写.newlines
)将允许您的代码进行编译。