我想在开始时创建种子前数据库文件非常大(5mb)。
我使用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
从 如何在iOS中显示复制大文件的进度?
- 在单独的线程中运行复制过程 (T1)
- 运行另一个定期读取的线程 (T2)(例如每 100 毫秒) 目标文件current_size。
- 计算百分比以显示进度:current_size/total_size