我在this教程和Apple docs中看到,这一堆代码应该可行。
let d = UIDocumentMenuViewController(documentTypes: [kUTTypeText as NSString], inMode: .Import)
o.delegate = self
self.presentViewController(d, animated: true, completion: nil)
但是我收到编译时错误
答案 0 :(得分:17)
kUTTypeText
在MobileCoreServices框架中定义,因此您应该添加
import MobileCoreServices
此外,正如Bartłomiej正确注意到的那样,必须转换类型标识符
从Swift 2 / Xcode 7中的CFString
到String
:
UIDocumentMenuViewController(documentTypes: [kUTTypeText as String], inMode: .Import)