Please find the code below.i by taking the link from @rmaddy's answer.
func CheckDataBaseOnPathorNot() -> Void { let bundlePath = Bundle.main.path(forResource: "Project_Expert", ofType: ".db") print(bundlePath ?? "", "\n") //prints the correct path let destPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! let fileManager = FileManager.default let fullDestPath = NSURL(fileURLWithPath: destPath).appendingPathComponent("Project_Expert.db") let fullDestPathString = fullDestPath!.path print(fileManager.fileExists(atPath: bundlePath!)) // prints true if fileManager.fileExists(atPath: fullDestPathString) { print("File is available") }else{ do{ try fileManager.copyItem(atPath: bundlePath!, toPath: fullDestPathString) }catch{ print("\n") print(error) } } }
Check this code if the file is not available in the path, and then copy the file.
Thanks.
source share