Я пытаюсь скопировать файл из моего пакета в каталог документов в iOS с помощью следующего кода.
let bundlePath = NSBundle.mainBundle().pathForResource("information", ofType: ".png")
print(bundlePath, "\n") //prints the correct path
let destPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first!
let fileManager = NSFileManager.defaultManager()
let fullDestPath = NSURL(fileURLWithPath: destPath).URLByAppendingPathComponent("information.png")
let fullDestPathString = String(fullDestPath)
print(fileManager.fileExistsAtPath(bundlePath!)) // prints true
do{
try fileManager.copyItemAtPath(bundlePath!, toPath: fullDestPathString)
}catch{
print("\n")
print(error)
}
Ошибка домена = NSCocoaErrorDomain Code = 4 «Файл« information.png »не существует». UserInfo = {NSSourceFilePathErrorKey = / Пользователи / macbookpro / Библиотека / Разработчик / CoreSimulator / Устройства / E58CA1C6-C6F1-4D72-9572-3925675E78A5 / data / Containers / Bundle / Приложение / EFA83E02-5F24-4BB3-B32A-7307/730. /information.png, NSUserStringVariant = (Копировать), NSDestinationFilePath = file: /// Пользователи / macbookpro / Библиотека / Разработчик / CoreSimulator / Устройства / E58CA1C6-C6F1-4D72-9572-3925675E78A5 / data / Containers / Data / Application / 86A1BDD5- FAF2-486E-85A9-CF72A547C6CD / Documents / information.png, NSFilePath = / Пользователи / macbookpro / Библиотека / Разработчик / CoreSimulator / Устройства / E58CA1C6-C6F1-4D72-9572-3925675E78A5 / данные / контейнеры / комплект / приложение / EFA83E02-5 -4BB3-B32A-7E755081A730 / AutoLayout tuts.app/information.png, NSUnderlyingError = 0x7fb53251cd80 {Ошибка домена = NSPOSIXErrorDomain Code = 2 "Нет такого файла или каталога"}}
Согласно fileManager.fileExistsAtPath()
файл действительно существует. Что я делаю не так?