Search code examples
iosstringswifticloud

Why UIDocumentMenuViewController does not accept kUTTypeText?


I saw in this tutorial and also in Apple docs, that this bunch of code should work.

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

But I get a compile time error

enter image description here


Solution

  • kUTTypeText is defined in the MobileCoreServices framework, so you should add

    import MobileCoreServices
    

    Also, as Bartłomiej correctly noticed, the type identifier has to be converted from CFString to String in Swift 2/Xcode 7:

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