Mike Mike - 8 months ago 91
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)



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