Search code examples
iosswiftxcodeuidocumentuidocumentpickerviewcontroller

how to initalise UIDocumentPickerViewController noting "forOpeningContentTypes" (from doco) seems to be deprecated in IOS?


When following the onsite IOS documentation for UIDocumentPickerViewController in Xcode 12.5.1 with IOS 14.5 deployment target I get an error:

Incorrect argument label in call (have 'forOpeningContentTypes:', expected 'forExporting:')

Any advice on how the usage of thie IOS UIDocumentPickerViewController is supposed to be used now?

My Code Except:

// Create a document picker for directories.
let documentPicker =
    UIDocumentPickerViewController(forOpeningContentTypes: [.folder])
documentPicker.delegate = self

Snapshot of error:

enter image description here

Documentation for how to use document picker here:

https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directories gives:


Solution

  • You forgot to

    import UniformTypeIdentifiers