6

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

1 Answer 1

22

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)
Sign up to request clarification or add additional context in comments.

6 Comments

for Swift you need to cast it also: documentTypes: [String(kUTTypeText)]
@BartłomiejSemańczyk: You are right (one of the many things that constantly change between Swift releases :) – Thanks for the feedback.
@MartinR Thank you, What a big shame that this essential information "import MobileCoreServices" no where on apple documentation!
Android Studio would offer to automatically add the required imports in such cases 😱
@Klaas: None that I know of.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.