为什么UIDocumentMenuViewController不接受kUTTypeText?

时间:2014-11-29 22:11:01

标签: ios string swift icloud

我在this教程和Apple docs中看到,这一堆代码应该可行。

let d = UIDocumentMenuViewController(documentTypes: [kUTTypeText as NSString], inMode: .Import)
o.delegate = self
self.presentViewController(d, animated: true, completion: nil)

但是我收到编译时错误

enter image description here

1 个答案:

答案 0 :(得分:17)

kUTTypeText在MobileCoreServices框架中定义,因此您应该添加

import MobileCoreServices

此外,正如Bartłomiej正确注意到的那样,必须转换类型标识符 从Swift 2 / Xcode 7中的CFStringString

UIDocumentMenuViewController(documentTypes: [kUTTypeText as String], inMode: .Import)