//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtype?language=objc)
// NS_TYPED_EXTENSIBLE_ENUM
pub type NSPasteboardType = NSString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypestring?language=objc)
    pub static NSPasteboardTypeString: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypepdf?language=objc)
    pub static NSPasteboardTypePDF: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypetiff?language=objc)
    pub static NSPasteboardTypeTIFF: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypepng?language=objc)
    pub static NSPasteboardTypePNG: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypertf?language=objc)
    pub static NSPasteboardTypeRTF: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypertfd?language=objc)
    pub static NSPasteboardTypeRTFD: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypehtml?language=objc)
    pub static NSPasteboardTypeHTML: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypetabulartext?language=objc)
    pub static NSPasteboardTypeTabularText: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypefont?language=objc)
    pub static NSPasteboardTypeFont: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtyperuler?language=objc)
    pub static NSPasteboardTypeRuler: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypecolor?language=objc)
    pub static NSPasteboardTypeColor: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypesound?language=objc)
    pub static NSPasteboardTypeSound: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypemultipletextselection?language=objc)
    pub static NSPasteboardTypeMultipleTextSelection: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypetextfinderoptions?language=objc)
    pub static NSPasteboardTypeTextFinderOptions: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypeurl?language=objc)
    pub static NSPasteboardTypeURL: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypefileurl?language=objc)
    pub static NSPasteboardTypeFileURL: &'static NSPasteboardType;
}

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardname?language=objc)
// NS_TYPED_EXTENSIBLE_ENUM
pub type NSPasteboardName = NSString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardnamegeneral?language=objc)
    pub static NSPasteboardNameGeneral: &'static NSPasteboardName;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardnamefont?language=objc)
    pub static NSPasteboardNameFont: &'static NSPasteboardName;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardnameruler?language=objc)
    pub static NSPasteboardNameRuler: &'static NSPasteboardName;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardnamefind?language=objc)
    pub static NSPasteboardNameFind: &'static NSPasteboardName;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardnamedrag?language=objc)
    pub static NSPasteboardNameDrag: &'static NSPasteboardName;
}

/// A value indicating pasteboard access behavior.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardaccessbehavior?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSPasteboardAccessBehavior(pub NSInteger);
impl NSPasteboardAccessBehavior {
    /// The default behavior for the General pasteboard is to ask upon programmatic access. All other pasteboards default to always allow access.
    /// If an app has never triggered a pasteboard access alert, its General pasteboard will report `.default` behavior. Such an app is not shown in the corresponding System Settings pane.
    /// Once programmatic pasteboard access triggers the first pasteboard access alert, the state automatically changes to `.ask`. At this point the app starts being shown in System Settings, where the user can toggle the behavior between `.ask`, `.alwaysAllow`, and `.alwaysDeny`.
    #[doc(alias = "NSPasteboardAccessBehaviorDefault")]
    pub const Default: Self = Self(0);
    /// The system will notify the user and ask for permission before granting pasteboard access. However, access that is both user originated and paste related will always be allowed, and will not result in a notification. The app is listed in the corresponding System Settings pane.
    #[doc(alias = "NSPasteboardAccessBehaviorAsk")]
    pub const Ask: Self = Self(1);
    /// The system will automatically allow all pasteboard access, without notifying the user.  The app is listed in the corresponding System Settings pane.
    #[doc(alias = "NSPasteboardAccessBehaviorAlwaysAllow")]
    pub const AlwaysAllow: Self = Self(2);
    /// The system will automatically deny all pasteboard access, without notifying the user. However, access that is both user originated and paste related will always be allowed, and will not result in a notification. The app is listed in the corresponding System Settings pane.
    #[doc(alias = "NSPasteboardAccessBehaviorAlwaysDeny")]
    pub const AlwaysDeny: Self = Self(3);
}

unsafe impl Encode for NSPasteboardAccessBehavior {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for NSPasteboardAccessBehavior {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// A pattern to detect on the pasteboard, such as a URL, text, or a number.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpattern?language=objc)
// NS_TYPED_ENUM
pub type NSPasteboardDetectionPattern = NSString;

extern "C" {
    /// A pattern that indicates the pasteboard detects a string that consists of a web URL.
    ///
    /// Returns: NSString value, suitable for implementing "Paste and Go"
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternprobableweburl?language=objc)
    pub static NSPasteboardDetectionPatternProbableWebURL: &'static NSPasteboardDetectionPattern;
}

extern "C" {
    /// A pattern that indicates the pasteboard detects a string suitable for use as a web search term.
    ///
    /// Returns: NSString value, suitable for implementing "Paste and Search"
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternprobablewebsearch?language=objc)
    pub static NSPasteboardDetectionPatternProbableWebSearch: &'static NSPasteboardDetectionPattern;
}

extern "C" {
    /// A pattern that indicates the pasteboard detects a string that consists of a numeric value.
    ///
    /// Returns: NSNumber value
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternnumber?language=objc)
    pub static NSPasteboardDetectionPatternNumber: &'static NSPasteboardDetectionPattern;
}

extern "C" {
    /// A pattern that indicates the pasteboard detects a string that contains a URL.
    ///
    /// Returns: array of DDMatchLink values
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternlink?language=objc)
    pub static NSPasteboardDetectionPatternLink: &'static NSPasteboardDetectionPattern;
}

extern "C" {
    /// A pattern that indicates the pasteboard detects a string that contains a phone number.
    ///
    /// Returns: array of DDMatchPhoneNumber values
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternphonenumber?language=objc)
    pub static NSPasteboardDetectionPatternPhoneNumber: &'static NSPasteboardDetectionPattern;
}

extern "C" {
    /// A pattern that indicates the pasteboard detects a string that contains an email address.
    ///
    /// Returns: array of DDMatchEmailAddress values
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternemailaddress?language=objc)
    pub static NSPasteboardDetectionPatternEmailAddress: &'static NSPasteboardDetectionPattern;
}

extern "C" {
    /// A pattern that indicates the pasteboard detects a string that contains a postal address.
    ///
    /// Returns: array of DDMatchPostalAddress values
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternpostaladdress?language=objc)
    pub static NSPasteboardDetectionPatternPostalAddress: &'static NSPasteboardDetectionPattern;
}

extern "C" {
    /// A pattern that indicates the pasteboard detects a string that contains a calendar event.
    ///
    /// Returns: array of DDMatchCalendarEvent values
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatterncalendarevent?language=objc)
    pub static NSPasteboardDetectionPatternCalendarEvent: &'static NSPasteboardDetectionPattern;
}

extern "C" {
    /// A pattern that indicates the pasteboard detects a string that contains a parcel tracking number and carrier.
    ///
    /// Returns: array of DDMatchShipmentTrackingNumber values
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternshipmenttrackingnumber?language=objc)
    pub static NSPasteboardDetectionPatternShipmentTrackingNumber:
        &'static NSPasteboardDetectionPattern;
}

extern "C" {
    /// A pattern that indicates the pasteboard detects a string that contains a flight number.
    ///
    /// Returns: array of DDMatchFlightNumber values
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternflightnumber?language=objc)
    pub static NSPasteboardDetectionPatternFlightNumber: &'static NSPasteboardDetectionPattern;
}

extern "C" {
    /// A pattern that indicates the pasteboard detects a string that contains an amount of money.
    ///
    /// Returns: array of DDMatchMoneyAmount values
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternmoneyamount?language=objc)
    pub static NSPasteboardDetectionPatternMoneyAmount: &'static NSPasteboardDetectionPattern;
}

/// A metadata type to detect on the pasteboard.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardmetadatatype?language=objc)
// NS_TYPED_ENUM
pub type NSPasteboardMetadataType = NSString;

extern "C" {
    /// A metadata type that returns the content type if the pasteboard detects a reference to a file.
    ///
    /// Returns: UTType value for the detected content type of the file URL, if a file URL type is present.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardmetadatatypecontenttype?language=objc)
    pub static NSPasteboardMetadataTypeContentType: &'static NSPasteboardMetadataType;
}

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardcontentsoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSPasteboardContentsOptions(pub NSUInteger);
bitflags::bitflags! {
    impl NSPasteboardContentsOptions: NSUInteger {
        #[doc(alias = "NSPasteboardContentsCurrentHostOnly")]
        const CurrentHostOnly = 1<<0;
    }
}

unsafe impl Encode for NSPasteboardContentsOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for NSPasteboardContentsOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardreadingoptionkey?language=objc)
// NS_TYPED_ENUM
pub type NSPasteboardReadingOptionKey = NSString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardurlreadingfileurlsonlykey?language=objc)
    pub static NSPasteboardURLReadingFileURLsOnlyKey: &'static NSPasteboardReadingOptionKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardurlreadingcontentsconformtotypeskey?language=objc)
    pub static NSPasteboardURLReadingContentsConformToTypesKey:
        &'static NSPasteboardReadingOptionKey;
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboard?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSPasteboard;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for NSPasteboard {}
);

impl NSPasteboard {
    extern_methods!(
        #[unsafe(method(generalPasteboard))]
        #[unsafe(method_family = none)]
        pub fn generalPasteboard() -> Retained<NSPasteboard>;

        #[unsafe(method(pasteboardWithName:))]
        #[unsafe(method_family = none)]
        pub fn pasteboardWithName(name: &NSPasteboardName) -> Retained<NSPasteboard>;

        #[unsafe(method(pasteboardWithUniqueName))]
        #[unsafe(method_family = none)]
        pub fn pasteboardWithUniqueName() -> Retained<NSPasteboard>;

        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub fn name(&self) -> Retained<NSPasteboardName>;

        #[unsafe(method(changeCount))]
        #[unsafe(method_family = none)]
        pub fn changeCount(&self) -> NSInteger;

        /// The current pasteboard access behavior. The user can customize this behavior per-app in System Settings for any app that has triggered a pasteboard access alert in the past.
        #[unsafe(method(accessBehavior))]
        #[unsafe(method_family = none)]
        pub fn accessBehavior(&self) -> NSPasteboardAccessBehavior;

        #[unsafe(method(prepareForNewContentsWithOptions:))]
        #[unsafe(method_family = none)]
        pub fn prepareForNewContentsWithOptions(
            &self,
            options: NSPasteboardContentsOptions,
        ) -> NSInteger;

        #[unsafe(method(clearContents))]
        #[unsafe(method_family = none)]
        pub fn clearContents(&self) -> NSInteger;

        #[unsafe(method(writeObjects:))]
        #[unsafe(method_family = none)]
        pub fn writeObjects(
            &self,
            objects: &NSArray<ProtocolObject<dyn NSPasteboardWriting>>,
        ) -> bool;

        /// # Safety
        ///
        /// - `class_array` generic probably has further requirements.
        /// - `options` generic should be of the correct type.
        #[unsafe(method(readObjectsForClasses:options:))]
        #[unsafe(method_family = none)]
        pub unsafe fn readObjectsForClasses_options(
            &self,
            class_array: &NSArray<AnyClass>,
            options: Option<&NSDictionary<NSPasteboardReadingOptionKey, AnyObject>>,
        ) -> Option<Retained<NSArray>>;

        #[cfg(feature = "NSPasteboardItem")]
        #[unsafe(method(pasteboardItems))]
        #[unsafe(method_family = none)]
        pub fn pasteboardItems(&self) -> Option<Retained<NSArray<NSPasteboardItem>>>;

        #[cfg(feature = "NSPasteboardItem")]
        #[unsafe(method(indexOfPasteboardItem:))]
        #[unsafe(method_family = none)]
        pub fn indexOfPasteboardItem(&self, pasteboard_item: &NSPasteboardItem) -> NSUInteger;

        #[unsafe(method(canReadItemWithDataConformingToTypes:))]
        #[unsafe(method_family = none)]
        pub fn canReadItemWithDataConformingToTypes(&self, types: &NSArray<NSString>) -> bool;

        /// # Safety
        ///
        /// - `class_array` generic probably has further requirements.
        /// - `options` generic should be of the correct type.
        #[unsafe(method(canReadObjectForClasses:options:))]
        #[unsafe(method_family = none)]
        pub unsafe fn canReadObjectForClasses_options(
            &self,
            class_array: &NSArray<AnyClass>,
            options: Option<&NSDictionary<NSPasteboardReadingOptionKey, AnyObject>>,
        ) -> bool;

        /// # Safety
        ///
        /// `new_owner` should be of the correct type.
        #[unsafe(method(declareTypes:owner:))]
        #[unsafe(method_family = none)]
        pub unsafe fn declareTypes_owner(
            &self,
            new_types: &NSArray<NSPasteboardType>,
            new_owner: Option<&AnyObject>,
        ) -> NSInteger;

        /// # Safety
        ///
        /// `new_owner` should be of the correct type.
        #[unsafe(method(addTypes:owner:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addTypes_owner(
            &self,
            new_types: &NSArray<NSPasteboardType>,
            new_owner: Option<&AnyObject>,
        ) -> NSInteger;

        #[unsafe(method(types))]
        #[unsafe(method_family = none)]
        pub fn types(&self) -> Option<Retained<NSArray<NSPasteboardType>>>;

        #[unsafe(method(availableTypeFromArray:))]
        #[unsafe(method_family = none)]
        pub fn availableTypeFromArray(
            &self,
            types: &NSArray<NSPasteboardType>,
        ) -> Option<Retained<NSPasteboardType>>;

        #[unsafe(method(setData:forType:))]
        #[unsafe(method_family = none)]
        pub fn setData_forType(&self, data: Option<&NSData>, data_type: &NSPasteboardType) -> bool;

        /// # Safety
        ///
        /// `plist` should be of the correct type.
        #[unsafe(method(setPropertyList:forType:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPropertyList_forType(
            &self,
            plist: &AnyObject,
            data_type: &NSPasteboardType,
        ) -> bool;

        #[unsafe(method(setString:forType:))]
        #[unsafe(method_family = none)]
        pub fn setString_forType(&self, string: &NSString, data_type: &NSPasteboardType) -> bool;

        #[unsafe(method(dataForType:))]
        #[unsafe(method_family = none)]
        pub fn dataForType(&self, data_type: &NSPasteboardType) -> Option<Retained<NSData>>;

        #[unsafe(method(propertyListForType:))]
        #[unsafe(method_family = none)]
        pub fn propertyListForType(
            &self,
            data_type: &NSPasteboardType,
        ) -> Option<Retained<AnyObject>>;

        #[unsafe(method(stringForType:))]
        #[unsafe(method_family = none)]
        pub fn stringForType(&self, data_type: &NSPasteboardType) -> Option<Retained<NSString>>;

        #[cfg(feature = "block2")]
        /// Determines whether the first pasteboard item matches the specified patterns, without notifying the person using the app.
        ///
        /// This method only gives an indication of whether the first pasteboard item matches a particular pattern, and doesn’t allow the app to access the item's contents. As a result, the system doesn’t notify the person using the app about reading the contents of the pasteboard.
        ///
        /// The following example shows how to use this method to find email and postal addresses in the first pasteboard item:
        ///
        /// ```obj-c
        /// [NSPasteboard.generalPasteboard
        /// detectPatternsForPatterns:[NSSet setWithArray:
        /// @
        /// [NSPasteboardDetectionPatternEmailAddress,
        /// NSPasteboardDetectionPatternPostalAddress]]
        /// completionHandler:^(NSSet
        /// <NSPasteboardDetectionPattern
        /// > *matchedPatterns, NSError *error) {
        /// if (error) {
        /// NSLog(
        /// "
        /// Error: %
        /// "
        /// , error);
        /// return;
        /// }
        /// BOOL matchedEmail = [matchedPatterns containsObject:NSPasteboardDetectionPatternEmailAddress];
        /// BOOL matchedPostal = [matchedPatterns containsObject: NSPasteboardDetectionPatternPostalAddress];
        /// if (matchedEmail) {
        /// NSLog(
        /// "
        /// Email address(es) detected");
        /// }
        /// if (matchedPostal) {
        /// NSLog(
        /// "
        /// Postal address(es) detected");
        /// }
        /// if (!matchedEmail
        /// &
        /// &
        /// !matchedPostal) {
        /// NSLog(
        /// "
        /// Matched neither email nor postal addresses.");
        /// }
        /// }];
        /// ```
        ///
        /// - Parameters:
        /// - patterns: The patterns to detect on the pasteboard.
        /// - completionHandler: A block the system invokes after detecting patterns on the pasteboard. The block receives either a set with the patterns the system finds on the pasteboard or an error if detection fails.
        #[unsafe(method(detectPatternsForPatterns:completionHandler:))]
        #[unsafe(method_family = none)]
        pub fn detectPatternsForPatterns_completionHandler(
            &self,
            patterns: &NSSet<NSPasteboardDetectionPattern>,
            completion_handler: &block2::DynBlock<
                dyn Fn(*mut NSSet<NSPasteboardDetectionPattern>, *mut NSError),
            >,
        );

        #[cfg(feature = "block2")]
        /// Determines whether the first pasteboard item matches the specified patterns, reading the contents if it finds a match.
        ///
        /// For details about the types returned for each pattern, see ``NSPasteboardDetectionPattern``.
        ///
        /// The following example shows how to use this method to find web URLs and web search terms in the first pasteboard item:
        ///
        /// ```obj-c
        /// [NSPasteboard.generalPasteboard
        /// detectValuesForPatterns:[NSSet setWithArray:
        /// @
        /// [NSPasteboardDetectionPatternProbableWebSearch,
        /// NSPasteboardDetectionPatternProbableWebURL]]
        /// completionHandler:^(NSDictionary
        /// <NSPasteboardDetectionPattern
        /// , id> *patternValues, NSError *error) {
        /// if (error) {
        /// NSLog(
        /// "
        /// Error: %
        /// "
        /// , error);
        /// return;
        /// }
        /// NSString *searchString = (NSString*)patternValues[NSPasteboardDetectionPatternProbableWebSearch];
        /// NSString *urlString = (NSString*)patternValues[NSPasteboardDetectionPatternProbableWebURL] ;
        /// if (searchString != nil) {
        /// NSLog(
        /// "
        /// Web search retrieved: %
        /// "
        /// , searchString);
        /// }
        /// if (urlString != nil) {
        /// NSLog(
        /// "
        /// Web URL retrieved: %
        /// "
        /// , urlString);
        /// }
        /// if (searchString == nil
        /// &
        /// &
        /// urlString == nil) {
        /// NSLog(
        /// "
        /// No web patterns retrieved.");
        /// }
        /// }];
        /// ```
        ///
        /// > Important: If the system finds a match when calling this method, the system informs the person using the app that the app is trying to read the contents of the pasteboard. If the person denies access to the pasteboard, the completion handler receives an error.
        ///
        /// - Parameters:
        /// - patterns: The patterns to detect on the pasteboard.
        /// - completionHandler: A block the system invokes after detecting patterns on the pasteboard. The block returns either a dictionary with the patterns the system finds on the pasteboard or an error if detection fails. The dictionary keys specify the matched patterns and the values specify the corresponding content of the pasteboard.
        #[unsafe(method(detectValuesForPatterns:completionHandler:))]
        #[unsafe(method_family = none)]
        pub fn detectValuesForPatterns_completionHandler(
            &self,
            patterns: &NSSet<NSPasteboardDetectionPattern>,
            completion_handler: &block2::DynBlock<
                dyn Fn(*mut NSDictionary<NSPasteboardDetectionPattern, AnyObject>, *mut NSError),
            >,
        );

        #[cfg(feature = "block2")]
        /// Determines available metadata from the specified metadata types for the first pasteboard item, without notifying the person using the app.
        ///
        /// This method only gives access to limited types of metadata and doesn’t allow the app to access the contents. As a result, the system doesn’t notify the person using the app about reading the contents of the pasteboard.
        ///
        /// For details about the metadata returned for each type, see ``NSPasteboardMetadataType``.
        ///
        /// The following example shows how to use this method to find the content type of a file reference in the first item on the pasteboard:
        ///
        /// ```obj-c
        /// [NSPasteboard.generalPasteboard
        /// detectMetadataForTypes:[NSSet setWithArray:
        /// @
        /// [NSPasteboardMetadataTypeContentType]]
        /// completionHandler:^(NSDictionary
        /// <NSPasteboardMetadataType
        /// , id> *metadata, NSError *error) {
        /// if (error) {
        /// NSLog(
        /// "
        /// Error: %
        /// "
        /// , error);
        /// return;
        /// }
        /// UTType *contentType = (UTType*)metadata[NSPasteboardMetadataTypeContentType];
        /// if (contentType) {
        /// NSLog(
        /// "
        /// Content type is: %
        /// "
        /// , contentType.identifier);
        /// } else {
        /// NSLog(
        /// "
        /// Couldn't get content type");
        /// }
        /// }];
        /// ```
        ///
        /// - Parameters:
        /// - types: The metadata types to detect on the pasteboard.
        /// - completionHandler: A block the system invokes after detecting metadata on the pasteboard. The block receives either a dictionary with the metadata types the system finds on the pasteboard or an error if detection fails. The dictionary keys specify the matched metadata types and the values specify the corresponding metadata.
        #[unsafe(method(detectMetadataForTypes:completionHandler:))]
        #[unsafe(method_family = none)]
        pub fn detectMetadataForTypes_completionHandler(
            &self,
            types: &NSSet<NSPasteboardMetadataType>,
            completion_handler: &block2::DynBlock<
                dyn Fn(*mut NSDictionary<NSPasteboardMetadataType, AnyObject>, *mut NSError),
            >,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl NSPasteboard {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for NSPasteboard {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// FilterServices.
impl NSPasteboard {
    extern_methods!(
        #[unsafe(method(typesFilterableTo:))]
        #[unsafe(method_family = none)]
        pub fn typesFilterableTo(r#type: &NSPasteboardType) -> Retained<NSArray<NSPasteboardType>>;

        #[unsafe(method(pasteboardByFilteringFile:))]
        #[unsafe(method_family = none)]
        pub fn pasteboardByFilteringFile(filename: &NSString) -> Retained<NSPasteboard>;

        #[unsafe(method(pasteboardByFilteringData:ofType:))]
        #[unsafe(method_family = none)]
        pub fn pasteboardByFilteringData_ofType(
            data: &NSData,
            r#type: &NSPasteboardType,
        ) -> Retained<NSPasteboard>;

        #[unsafe(method(pasteboardByFilteringTypesInPasteboard:))]
        #[unsafe(method_family = none)]
        pub fn pasteboardByFilteringTypesInPasteboard(
            pboard: &NSPasteboard,
        ) -> Retained<NSPasteboard>;
    );
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypeowner?language=objc)
    pub unsafe trait NSPasteboardTypeOwner: NSObjectProtocol {
        #[unsafe(method(pasteboard:provideDataForType:))]
        #[unsafe(method_family = none)]
        fn pasteboard_provideDataForType(&self, sender: &NSPasteboard, r#type: &NSPasteboardType);

        #[optional]
        #[unsafe(method(pasteboardChangedOwner:))]
        #[unsafe(method_family = none)]
        fn pasteboardChangedOwner(&self, sender: &NSPasteboard);
    }
);

/// * NSPasteboardWriting and NSPasteboardReading Protocols **
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardwritingoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSPasteboardWritingOptions(pub NSUInteger);
bitflags::bitflags! {
    impl NSPasteboardWritingOptions: NSUInteger {
        #[doc(alias = "NSPasteboardWritingPromised")]
        const Promised = 1<<9;
    }
}

unsafe impl Encode for NSPasteboardWritingOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for NSPasteboardWritingOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardwriting?language=objc)
    pub unsafe trait NSPasteboardWriting: NSObjectProtocol {
        #[unsafe(method(writableTypesForPasteboard:))]
        #[unsafe(method_family = none)]
        fn writableTypesForPasteboard(
            &self,
            pasteboard: &NSPasteboard,
        ) -> Retained<NSArray<NSPasteboardType>>;

        #[optional]
        #[unsafe(method(writingOptionsForType:pasteboard:))]
        #[unsafe(method_family = none)]
        fn writingOptionsForType_pasteboard(
            &self,
            r#type: &NSPasteboardType,
            pasteboard: &NSPasteboard,
        ) -> NSPasteboardWritingOptions;

        #[unsafe(method(pasteboardPropertyListForType:))]
        #[unsafe(method_family = none)]
        fn pasteboardPropertyListForType(
            &self,
            r#type: &NSPasteboardType,
        ) -> Option<Retained<AnyObject>>;
    }
);

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardreadingoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSPasteboardReadingOptions(pub NSUInteger);
bitflags::bitflags! {
    impl NSPasteboardReadingOptions: NSUInteger {
        #[doc(alias = "NSPasteboardReadingAsData")]
        const AsData = 0;
        #[doc(alias = "NSPasteboardReadingAsString")]
        const AsString = 1<<0;
        #[doc(alias = "NSPasteboardReadingAsPropertyList")]
        const AsPropertyList = 1<<1;
        #[doc(alias = "NSPasteboardReadingAsKeyedArchive")]
        const AsKeyedArchive = 1<<2;
    }
}

unsafe impl Encode for NSPasteboardReadingOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for NSPasteboardReadingOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardreading?language=objc)
    pub unsafe trait NSPasteboardReading: NSObjectProtocol {
        #[unsafe(method(readableTypesForPasteboard:))]
        #[unsafe(method_family = none)]
        fn readableTypesForPasteboard(
            pasteboard: &NSPasteboard,
        ) -> Retained<NSArray<NSPasteboardType>>;

        #[optional]
        #[unsafe(method(readingOptionsForType:pasteboard:))]
        #[unsafe(method_family = none)]
        fn readingOptionsForType_pasteboard(
            r#type: &NSPasteboardType,
            pasteboard: &NSPasteboard,
        ) -> NSPasteboardReadingOptions;

        /// # Safety
        ///
        /// `property_list` should be of the correct type.
        #[optional]
        #[unsafe(method(initWithPasteboardPropertyList:ofType:))]
        #[unsafe(method_family = init)]
        unsafe fn initWithPasteboardPropertyList_ofType(
            this: Allocated<Self>,
            property_list: &AnyObject,
            r#type: &NSPasteboardType,
        ) -> Option<Retained<Self>>;
    }
);

mod private_NSURLNSPasteboardSupport {
    pub trait Sealed {}
}

/// Category "NSPasteboardSupport" on [`NSURL`].
#[doc(alias = "NSPasteboardSupport")]
pub unsafe trait NSURLNSPasteboardSupport:
    ClassType + Sized + private_NSURLNSPasteboardSupport::Sealed
{
    extern_methods!(
        #[unsafe(method(URLFromPasteboard:))]
        #[unsafe(method_family = none)]
        fn URLFromPasteboard(paste_board: &NSPasteboard) -> Option<Retained<NSURL>>;

        #[unsafe(method(writeToPasteboard:))]
        #[unsafe(method_family = none)]
        fn writeToPasteboard(&self, paste_board: &NSPasteboard);
    );
}

impl private_NSURLNSPasteboardSupport::Sealed for NSURL {}
unsafe impl NSURLNSPasteboardSupport for NSURL {}

extern_conformance!(
    unsafe impl NSPasteboardReading for NSURL {}
);

extern_conformance!(
    unsafe impl NSPasteboardWriting for NSURL {}
);

extern_conformance!(
    unsafe impl NSPasteboardReading for NSString {}
);

extern_conformance!(
    unsafe impl NSPasteboardWriting for NSString {}
);

/// NSFileContents.
///
/// * File Contents **
impl NSPasteboard {
    extern_methods!(
        #[unsafe(method(writeFileContents:))]
        #[unsafe(method_family = none)]
        pub fn writeFileContents(&self, filename: &NSString) -> bool;

        #[unsafe(method(readFileContentsType:toFile:))]
        #[unsafe(method_family = none)]
        pub fn readFileContentsType_toFile(
            &self,
            r#type: Option<&NSPasteboardType>,
            filename: &NSString,
        ) -> Option<Retained<NSString>>;

        #[unsafe(method(writeFileWrapper:))]
        #[unsafe(method_family = none)]
        pub fn writeFileWrapper(&self, wrapper: &NSFileWrapper) -> bool;

        #[unsafe(method(readFileWrapper))]
        #[unsafe(method_family = none)]
        pub fn readFileWrapper(&self) -> Option<Retained<NSFileWrapper>>;
    );
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfilecontentspboardtype?language=objc)
    pub static NSFileContentsPboardType: &'static NSPasteboardType;
}

#[inline]
pub extern "C-unwind" fn NSCreateFilenamePboardType(
    file_type: &NSString,
) -> Option<Retained<NSPasteboardType>> {
    extern "C-unwind" {
        fn NSCreateFilenamePboardType(file_type: &NSString) -> *mut NSPasteboardType;
    }
    let ret = unsafe { NSCreateFilenamePboardType(file_type) };
    unsafe { Retained::from_raw(ret) }
}

#[inline]
pub extern "C-unwind" fn NSCreateFileContentsPboardType(
    file_type: &NSString,
) -> Option<Retained<NSPasteboardType>> {
    extern "C-unwind" {
        fn NSCreateFileContentsPboardType(file_type: &NSString) -> *mut NSPasteboardType;
    }
    let ret = unsafe { NSCreateFileContentsPboardType(file_type) };
    unsafe { Retained::from_raw(ret) }
}

#[inline]
pub extern "C-unwind" fn NSGetFileType(
    pboard_type: &NSPasteboardType,
) -> Option<Retained<NSString>> {
    extern "C-unwind" {
        fn NSGetFileType(pboard_type: &NSPasteboardType) -> *mut NSString;
    }
    let ret = unsafe { NSGetFileType(pboard_type) };
    unsafe { Retained::retain_autoreleased(ret) }
}

#[inline]
pub extern "C-unwind" fn NSGetFileTypes(
    pboard_types: &NSArray<NSPasteboardType>,
) -> Option<Retained<NSArray<NSString>>> {
    extern "C-unwind" {
        fn NSGetFileTypes(pboard_types: &NSArray<NSPasteboardType>) -> *mut NSArray<NSString>;
    }
    let ret = unsafe { NSGetFileTypes(pboard_types) };
    unsafe { Retained::retain_autoreleased(ret) }
}

extern "C" {
    /// * Deprecated **
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstringpboardtype?language=objc)
    #[deprecated]
    pub static NSStringPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfilenamespboardtype?language=objc)
    #[deprecated = "Create multiple pasteboard items with NSPasteboardTypeFileURL or kUTTypeFileURL instead"]
    pub static NSFilenamesPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstiffpboardtype?language=objc)
    #[deprecated]
    pub static NSTIFFPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsrtfpboardtype?language=objc)
    #[deprecated]
    pub static NSRTFPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstabulartextpboardtype?language=objc)
    #[deprecated]
    pub static NSTabularTextPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfontpboardtype?language=objc)
    #[deprecated]
    pub static NSFontPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsrulerpboardtype?language=objc)
    #[deprecated]
    pub static NSRulerPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nscolorpboardtype?language=objc)
    #[deprecated]
    pub static NSColorPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsrtfdpboardtype?language=objc)
    #[deprecated]
    pub static NSRTFDPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nshtmlpboardtype?language=objc)
    #[deprecated]
    pub static NSHTMLPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsurlpboardtype?language=objc)
    #[deprecated]
    pub static NSURLPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspdfpboardtype?language=objc)
    #[deprecated]
    pub static NSPDFPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmultipletextselectionpboardtype?language=objc)
    #[deprecated]
    pub static NSMultipleTextSelectionPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspostscriptpboardtype?language=objc)
    #[deprecated]
    pub static NSPostScriptPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsvcardpboardtype?language=objc)
    #[deprecated]
    pub static NSVCardPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsinktextpboardtype?language=objc)
    #[deprecated]
    pub static NSInkTextPboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfilespromisepboardtype?language=objc)
    #[deprecated]
    pub static NSFilesPromisePboardType: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypefindpanelsearchoptions?language=objc)
    #[deprecated]
    pub static NSPasteboardTypeFindPanelSearchOptions: &'static NSPasteboardType;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsgeneralpboard?language=objc)
    #[deprecated]
    pub static NSGeneralPboard: &'static NSPasteboardName;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfontpboard?language=objc)
    #[deprecated]
    pub static NSFontPboard: &'static NSPasteboardName;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsrulerpboard?language=objc)
    #[deprecated]
    pub static NSRulerPboard: &'static NSPasteboardName;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfindpboard?language=objc)
    #[deprecated]
    pub static NSFindPboard: &'static NSPasteboardName;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsdragpboard?language=objc)
    #[deprecated]
    pub static NSDragPboard: &'static NSPasteboardName;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspictpboardtype?language=objc)
    #[deprecated]
    pub static NSPICTPboardType: &'static NSPasteboardType;
}
