'value of type 'NSOpenPanel' has no member 'allowedContentTypes'

If a try to set the allowedContentTypes for an NSOpenPanel, I get always the message that this isn't a member. I cannot use the openPanel.allowedFileTypes because it is deprecated. I didn't change any setting for the project. It was defined primary as an empty object, and then a added a macOS target In the source I only import Cocoa

See code:

let openPanel = NSOpenPanel()
    openPanel.title = "SelectImageTitle"
    openPanel.prompt = "SelectImagePrompt"
    openPanel.nameFieldLabel = "SelectImageLabel"
    openPanel.showsResizeIndicator = true
    openPanel.showsHiddenFiles = false
    openPanel.allowsMultipleSelection = false
    openPanel.canChooseDirectories = false
    //openPanel.allowedFileTypes = allowedImageTypes
    openPanel.allowedContentTypes = [.png]
//  openPanel
    //----- Perform the selection dialog    ----------------------------------------------------------------------------
    guard openPanel.runModal() == .OK else { return nil }
    return openPanel.url?.path


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source