从Bundle复制文件时Swift FileManager错误
发布时间:2020-12-14 02:24:50 所属栏目:百科 来源:网络整理
导读:我正在尝试将我的App的Bundle中的文件复制到设备上,我收到一个奇怪的错误:无法将表达式’$T5’转换为’LogicValue’类型 我评论了下面代码中导致问题的那一行. 这是一切: // This function returns the path to the Documents folder:func pathToDocsFolde
我正在尝试将我的App的Bundle中的文件复制到设备上,我收到一个奇怪的错误:无法将表达式’$T5’转换为’LogicValue’类型
我评论了下面代码中导致问题的那一行. 这是一切: // This function returns the path to the Documents folder: func pathToDocsFolder() -> String { let pathToDocumentsFolder = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0] as String return pathToDocumentsFolder.stringByAppendingPathComponent("/moviesDataBase.sqlite") } override func viewDidLoad() { super.viewDidLoad() let theFileManager = NSFileManager.defaultManager() if theFileManager.fileExistsAtPath(pathToDocsFolder()) { println("File Found!") // And then open the DB File } else { // Copy the file from the Bundle and write it to the Device: let pathToBundledDB = NSBundle.mainBundle().pathForResource("moviesDB",ofType: "sqlite") let pathToDevice = pathToDocsFolder() let error:NSError? // Here is where I get the error: if (theFileManager.copyItemAtPath(pathToBundledDB,toPath:pathToDevice,error:error)) { // success } else { // failure } } } 该应用程序甚至不会立即编译.这个问题似乎特别针对copyItemAtPath调用 – 它应该返回一个Bool. 我很欣赏任何见解.
这里有两个问题:
>如果您将错误变量指定为let,则它不可变,因此您无法获得错误值.>您应该发送指向错误变量的指针,而不是变量本身.因此,在您收到编译器错误的行中,它应该是& error而不是error. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- JRuby on Rails:在Rails应用程序中使用自定义Java类
- AJAX实例:用callback函数的AJAX实例
- ruby-on-rails – JasmineRice on Rails 4
- 正则引擎对比
- Flash开发iOS应用全攻略(三)——如何使用iOS开发者授权以
- ruby-on-rails – Heroku rails 3.1应用程序 – 在本地编译
- objective-c – 如何为对象指针指针(id *)选择ARC桥接说明符
- postgresql – Windows的好Postgres图形客户端
- c# – 为什么我会收到异常:在webclient上尝试过多的自动重
- xstream 对XML提供特殊解析