【问题标题】:Why UIDocumentMenuViewController does not accept kUTTypeText?为什么 UIDocumentMenuViewController 不接受 kUTTypeText?
【发布时间】:2015-01-28 05:41:33
【问题描述】:

我在this 教程和Apple docs 中看到,这组代码应该可以工作。

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

但是我得到一个编译时错误

【问题讨论】:

    标签: ios string swift icloud


    【解决方案1】:

    kUTTypeText是在MobileCoreServices框架中定义的,所以你应该添加

    import MobileCoreServices
    

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

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

    【讨论】:

    • 对于 Swift 你还需要强制转换:documentTypes: [String(kUTTypeText)]
    • @BartłomiejSemańczyk:你是对的(在 Swift 版本之间不断变化的许多事情之一 :) - 感谢您的反馈。
    • @MartinR 谢谢,苹果文档中没有“导入 MobileCoreServices”这一重要信息真是太可惜了!
    • Android Studio 会在这种情况下自动添加所需的导入 ?
    • @Klaas:我不知道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2011-06-28
    • 1970-01-01
    • 2022-09-23
    相关资源
    最近更新 更多