我正在尝试从名为CSV
的简单data.txt
文本文件中读取数据,该文件保存在我的主文件夹中。我收到错误“使用未解析的标识符'contentsOfFile',如代码所示
我哪里错了?
//MARK: Data reading and writing functions
func readDataFromFile(fileName:String) -> String!{
guard let filepath = Bundle.main.path(forResource: fileName, ofType: "txt")
else {return nil}
do { //Error showing following line
let contents = try String(contentsOfFile: filepath, encoding: String.Encoding.utf8)
return contents
}catch{
print ("File Read Error")
return nil
}
}