Search code examples
ioscocoa-touchfilehandlefile-manager

How much data will FileManager file save?


I am using FileManager in Ios to create dir and save my log files in it.. When I get String data that I what I am appending it to the file that I have in FileManager dir .. Can i know How much data that I can append and also What happens If it that file has more data then it's limit .. Please help me out.. Is there any way to know my Iphone storage limit while using filemanager?


Solution

  • There is no real limit for file sizes. You can write to the file system until all storage space is used up. You can append a string to a file with:

    FileManager.default.createFile(atPath: filePath, contents: nil, attributes: nil)
    let fileHandle = FileHandle(forWritingAtPath: filePath)!
    let string = "test"
    let data = string.data(using: .utf8)!
    fileHandle.seekToEndOfFile()
    fileHandle.write(data)
    fileHandle.closeFile()