【发布时间】:2016-11-28 00:07:55
【问题描述】:
@IBAction func iCloudPlayer(_ sender: Any) {
var documentPicker = UIDocumentPickerViewController(documentTypes: ["public.txt"], in: UIDocumentPickerMode.import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = UIModalPresentationStyle.fullScreen
self.present(documentPicker, animated: true, completion: nil)
}
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL){
if(controller.documentPickerMode == UIDocumentPickerMode.import){
let content = openFile(path: url.path, UTF8: String.Encoding.utf8)
titlePlayerContent.text = content
}
}
func openFile(path:String, UTF8:String.Encoding = String.Encoding.utf8) -> String?{
var error: NSError?
return FileManager().fileExists(atPath: path) ? String(contentsOfFile: path, encoding: UTF8, error: &error)! : nil
}
//参数标签'(contentsOfFile;,encoding;, erro:)' 不匹配任何可用的重载,error on ?字符串(contentsOfFile:路径,编码:UTF8,错误:&error)! : 无
有什么建议吗?我如何从 iCloud 上传,教程不适用于 Swift 3!
【问题讨论】:
-
您是否查看过 Swift 3 文档中的
String及其init方法? -
你的问题与
UIDocumentPickerViewController或iCloud无关。