Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kUTTypeURL undefined — Use of unresolved identifier 'kUTTypeURL' in Swift

Tags:

ios

swift

ios8

I'm having trouble getting a sharing extension to work. I have the following in my sharing controller.

let item: NSExtensionItem = self.extensionContext.inputItems[0] as NSExtensionItem
let itemProvider: NSItemProvider = item.attachments[0] as NSItemProvider
var URL: NSString
if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeURL) {
  itemProvider.loadItemForTypeIdentifier(kUTTypeURL, options: nil, completionHandler:   {(url: NSURL, error: NSError) in
     URL = url.absoluteString
  })
}

self.extensionContext.completeRequestReturningItems(nil, completionHandler: nil)

This gives me the error Use of unresolved identifier 'kUTTypeURL' on the line if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeURL) {.

It seems to be defined as a constant in Swift, but I can't seem to access it. Is it part of an enum? Do I have to import something to get access to it?

Thanks for your help.

like image 859
matthewpalmer Avatar asked Jul 10 '14 23:07

matthewpalmer


1 Answers

Just so this question has an answer:

Add import MobileCoreServices to your source file.

like image 149
sbooth Avatar answered Nov 14 '22 11:11

sbooth