writeToFile how to tell when it is completed

前端 未结 2 394
误落风尘
误落风尘 2021-01-17 11:11

I\'m doing some writing of data to my documents directory and I was wondering if there is a way to tell when my writeToFile method completes and the file I am creating has b

相关标签:
2条回答
  • 2021-01-17 11:14

    The method writeToFile:atomically is "synchronous". It will write the file and then return YES or NO depending on wether the file was successfully written or not.

    That means that the operation is complete as soon as the method returns.

    BOOL success = [imageData writeToFile:fullPathToFile atomically:YES];
    // Now, the operation is complete
    // success indicates whether the file was successfully written or not
    
    0 讨论(0)
  • 2021-01-17 11:27

    Swift 5:

    do {
        try data.write(to: path)
        // here's when write operation is completed without errors thrown
    } catch {
        Swift.print(error)
    }
    
    0 讨论(0)
提交回复
热议问题