How to copy the file from appBundle to document directory iOS swift?

Solution:

If you want copy the file that you had already added to your bundle to the document directory then follow the code.Below i had copied the first.wav file from bundle directory to document directory.

Code:
        let destPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
        let fileManager = FileManager.default

        //beep sound copy
        let bundlePath = Bundle.main.path(forResource: "first", ofType: ".wav")
        let fullDestPath = NSURL(fileURLWithPath: destPath).appendingPathComponent("first.wav")

        do{
            try fileManager.copyItem(atPath: bundlePath!, toPath: (fullDestPath?.path)!)

        }catch{
            print("\n")
            print(error)
        }

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift