Barak
Barak

Reputation: 517

Check if -[NSData writeToFile:atomically:] is done

-(void)WriteToFile:(NSString*)fileName andString:(NSString*)array{
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.txt",fileName]];
    NSData *serializedData = [NSKeyedArchiver archivedDataWithRootObject:array];
    [serializedData writeToFile:filePath atomically:YES];
}

I have a big NSString that I want to write to a text file. How do I check if it is already done?

Upvotes: 0

Views: 568

Answers (1)

jscs
jscs

Reputation: 64002

-[NSData writeToFile:atomically:] doesn't return until the write has either completed or failed. Until control passes back to your code, the operation is still running.

Check the returned BOOL to see if the write has succeeded.

Upvotes: 1

Related Questions