I want to create pre-seed database at the beginning The file is quite large (5mb).
I use copyItemAtPath
to copy files, so do this method has completion?
How do i know when this process has been finished?
I want to create pre-seed database at the beginning The file is quite large (5mb).
I use copyItemAtPath
to copy files, so do this method has completion?
How do i know when this process has been finished?
This code is enough:
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)")
}
where destinationPath can be for example:
NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, .UserDomainMask, true).first
From How to show the progress of copying a large file in iOS?
- Run your copying process in a seperate thread (T1)
- Run another thread (T2) which reads periodically (say every 100ms) the destination file current_size.
- Calculate the percentage to display progress: current_size / total_size