Mike Mike - 1 year ago 204
Swift Question

Why UIDocumentMenu Delegate to self doesn't work?

I am following Apple documentation for UIDocumentMenuViewController and the following is my code. importMenu.delegate = self doesn't work and Xcode shows: Cannot assign value of type 'ViewController' to type 'UIDocumentMenuDelegate?' . Please help. Thanks!

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {

let importMenu = UIDocumentMenuViewController(documentTypes: ["public.text", "public.data"], inMode: .Import)

importMenu.delegate = self

self.presentViewController(importMenu, animated: true, completion: nil)


Answer Source

According to UIDocumentMenuDelegate Protocol Reference, your ViewController must conforms to UIDocumentMenuDelegate and must implements documentMenu:didPickDocumentPicker:

extension ViewController: UIDocumentMenuDelegate {
    func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
        // do stuffs here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download