1
我想在開始時創建預種子數據庫 該文件相當大(5mb)。iOS - Swift如何知道copyItemAtPath何時完成?
我用copyItemAtPath
來複制文件,那麼這個方法有沒有完成? 我如何知道這個過程已經完成?
我想在開始時創建預種子數據庫 該文件相當大(5mb)。iOS - Swift如何知道copyItemAtPath何時完成?
我用copyItemAtPath
來複制文件,那麼這個方法有沒有完成? 我如何知道這個過程已經完成?
這段代碼就足夠了:
do {
// copy files from main bundle to documents directory
print("copy")
try
NSFileManager.defaultManager().copyItemAtPath(sourcePath, toPath: destinationPath)
} catch let error as NSError {
// Catch fires here, with an NSError being thrown
print("error occurred, here are the details:\n \(error)")
}
其中的DestinationPath可以是例如:
NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, .UserDomainMask, true).first
從How to show the progress of copying a large file in iOS?
- 在一個單獨的線程中運行你的複製過程(T1 )
- 運行另一個線程(T2),定期讀取(比如說每100ms) 目標文件current_size。
- 計算顯示百分比進度:current_size/TOTAL_SIZE
當copyItemAtPath方法返回,它不是異步複製完成。如何通過拋出錯誤來報告失敗? –