How to append fast updating strings to file in swift

后端 未结 2 459
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 08:04

I want to write sensor data to a file as the sensor updates within the method. I need to append the data as it updates, but my file overwrites with the last sensor output when I

2条回答
  •  半阙折子戏
    2021-01-26 08:31

    Use seekToEndOfFile

    let myHandle = FileHandle.init(forWritingAtPath: fileUrl.path)
    
    myHandle.seekToEndOfFile 
    
    myHandle.write(strTowrite.data(using: String.Encoding.utf8)!)
    
    myHandle.closeFile()
    

提交回复
热议问题