Here is my code for copying the folder from bundle to libraries.
let library = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask)[0]
let bundle = Bundle.main.path(forResource: "MYFOLDER", ofType: "")!
let fileManager = FileManager.default
do
{
try fileManager.copyItem(atPath: bundle, toPath: library.path)
print("NO CATCH")
}
catch
{
print(error)
}
I get this error:
Error Domain=NSCocoaErrorDomain Code=516 "“MYFOLDER” couldn’t be copied to “CBE6D212-8827-423B-AEC8-6830EED0EC5C” because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=/Users/Joshua/Library/Developer/CoreSimulator/Devices/84EF61E3-6739-47D1-A0AE-1215B89D0CE7/data/Containers/Bundle/Application/C357EB0E-6719-464B-8DC9-513E5E7F83E1/Heffy.app/MYFOLDER, NSUserStringVariant=( Copy ), NSFilePath=/Users/Joshua/Library/Developer/CoreSimulator/Devices/84EF61E3-6739-47D1-A0AE-1215B89D0CE7/data/Containers/Bundle/Application/C357EB0E-6719-464B-8DC9-513E5E7F83E1/Heffy.app/MYFOLDER, NSDestinationFilePath=/Users/Joshua/Library/Developer/CoreSimulator/Devices/84EF61E3-6739-47D1-A0AE-1215B89D0CE7/data/Containers/Data/Application/CBE6D212-8827-423B-AEC8-6830EED0EC5C/Library, NSUnderlyingError=0x797878e0 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}
**BUT I CHECKED IT DOES NOT EXIST IN THE LIBRARY FOLDER*
As per your error, file is already existing. try this code and check