2012-04-06 5 views
16

내 문서 디렉토리에 데이터를 쓰는 중입니다. writeToFile 메서드가 완료되고 작성중인 파일이 완전히 만들어 졌는지 알 수있는 방법이 있는지 궁금합니다. 미리 감사드립니다. 여기에 제가 호출하는 메서드가 있습니다.이 메서드는 위임 메서드 또는이 완료 시점을 알려주는 다른 방법 일뿐입니다.writeToFile 완료 시점을 알려주는 방법

[imageData writeToFile:fullPathToFile atomically:YES]; 

답변

31

있어서 writeToFile:atomically는 "동기"이다. 파일을 쓰고 파일이 성공적으로 기록되었는지 여부에 따라 YES 또는 NO을 반환합니다.

즉, 메서드가 반환 되 자마자 작업이 완료되었음을 의미합니다.

BOOL success = [imageData writeToFile:fullPathToFile atomically:YES]; 
// Now, the operation is complete 
// success indicates whether the file was successfully written or not 
+1

저장이 실패 할 경우 오류 로그를 얻을 수있는 방법이 있습니까? – aneuryzm

+3

@ 패트릭 [writeToFile : options : error :] (https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html#/) 메소드를 사용할 수 있습니다./apple_ref/occ/instm/NSData/writeToFile : 옵션 : 오류 :) – sch

관련 문제