Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writeToFile how to tell when it is completed

Tags:

ios

iphone

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 be fully created. Thanks in advance here is the method I am calling I am just looking for a way wether it is a delegate method or some other way to tell when this completes.

[imageData writeToFile:fullPathToFile atomically:YES];

Nick

like image 753
Krzemienski Avatar asked Apr 06 '12 21:04

Krzemienski


2 Answers

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
like image 71
sch Avatar answered Oct 21 '22 02:10

sch


Swift 5:

do {
    try data.write(to: path)
    // here's when write operation is completed without errors thrown
} catch {
    Swift.print(error)
}
like image 5
atereshkov Avatar answered Oct 21 '22 02:10

atereshkov