Status bar could not find cached time string image. Rendering in-process.
/csvファイル
func createcsv(acceleration: CMAcceleration){
let fm = FileManager.default
//documents
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
let filePath = documentsPath + "/getdata.csv"
if !fm.fileExists(atPath: filePath) {
fm.createFile(atPath: filePath, contents: nil, attributes: [:]) }
var X = acceleration.x
var Y = acceleration.y
var Z = acceleration.z
let getdata = "(X),(Y),(Z)\n"
do{
try getdata.write(toFile: filePath, atomically: true, encoding: String.Encoding.utf8)
print("Success to Wite the File")
}catch let error as NSError{
print("Failure to Write File\n(error)")
}
}
今実機が手元にないので試せなくて申し訳ないのですが。
let getdata = "\(X),\(Y),\(Z)\n"
の下で、print(getdata) とするとどうなりますか?
エラーについて:Xcode 9.3ですか? This bug is present in XCode 9.3, also it is resolved in 9.4 beta.とありますよ。
1// ラベルのoutlet接続2@IBOutletweakvar xValueLabel:UILabel!3@IBOutletweakvar yValueLabel:UILabel!4@IBOutletweakvar zValueLabel:UILabel!5678// ボタンタップ時にラベルの値を取得してCSVに保存する。9@IBActionfuncsaveCSV(_ sender:UIButton){10let fm =FileManager.default11//documents12let documentsPath =NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask,true).first!13let filePath = documentsPath +"/getdata.csv"14if!fm.fileExists(atPath: filePath){15 fm.createFile(atPath: filePath, contents:nil, attributes:[:])}1617//let X = acceleration.x18//let Y = acceleration.y19//let Z = acceleration.z20//let getdata = "(X),(Y),(Z)\n"2122let X = xValueLabel.text ??""23let Y = yValueLabel.text ??""24let Z = zValueLabel.text ??""25let getdata = X + Y + Z
2627print("getdata:",getdata)2829do{30try getdata.write(toFile: filePath, atomically:true, encoding:String.Encoding.utf8)31print("filePath:",filePath)32print("Success to Wite the File")33}catchlet error asNSError{34print("Failure to Write File\n(error)")35}36}37