objc2-foundation 0.3.2

Bindings to the Foundation framework
Documentation
//! 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 crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnotificationname?language=objc)
// NS_TYPED_EXTENSIBLE_ENUM
#[cfg(feature = "NSString")]
pub type NSNotificationName = NSString;

extern_class!(
    /// **************    Notifications    ***************
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnotification?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSNotification;
);

#[cfg(feature = "NSObject")]
extern_conformance!(
    unsafe impl NSCoding for NSNotification {}
);

#[cfg(feature = "NSObject")]
extern_conformance!(
    unsafe impl NSCopying for NSNotification {}
);

#[cfg(feature = "NSObject")]
unsafe impl CopyingHelper for NSNotification {
    type Result = Self;
}

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

impl NSNotification {
    extern_methods!(
        #[cfg(feature = "NSString")]
        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub fn name(&self) -> Retained<NSNotificationName>;

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

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

        #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
        /// # Safety
        ///
        /// - `object` should be of the correct type.
        /// - `user_info` generic should be of the correct type.
        #[unsafe(method(initWithName:object:userInfo:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithName_object_userInfo(
            this: Allocated<Self>,
            name: &NSNotificationName,
            object: Option<&AnyObject>,
            user_info: Option<&NSDictionary>,
        ) -> Retained<Self>;

        #[cfg(feature = "NSCoder")]
        /// # Safety
        ///
        /// `coder` possibly has further requirements.
        #[unsafe(method(initWithCoder:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoder(
            this: Allocated<Self>,
            coder: &NSCoder,
        ) -> Option<Retained<Self>>;
    );
}

/// NSNotificationCreation.
impl NSNotification {
    extern_methods!(
        #[cfg(feature = "NSString")]
        /// # Safety
        ///
        /// `an_object` should be of the correct type.
        #[unsafe(method(notificationWithName:object:))]
        #[unsafe(method_family = none)]
        pub unsafe fn notificationWithName_object(
            a_name: &NSNotificationName,
            an_object: Option<&AnyObject>,
        ) -> Retained<Self>;

        #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
        /// # Safety
        ///
        /// - `an_object` should be of the correct type.
        /// - `a_user_info` generic should be of the correct type.
        #[unsafe(method(notificationWithName:object:userInfo:))]
        #[unsafe(method_family = none)]
        pub unsafe fn notificationWithName_object_userInfo(
            a_name: &NSNotificationName,
            an_object: Option<&AnyObject>,
            a_user_info: Option<&NSDictionary>,
        ) -> Retained<Self>;
    );
}

extern_class!(
    /// **************    Notification Center    ***************
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsnotificationcenter?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSNotificationCenter;
);

unsafe impl Send for NSNotificationCenter {}

unsafe impl Sync for NSNotificationCenter {}

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

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

        #[cfg(feature = "NSString")]
        /// # Safety
        ///
        /// - `observer` should be of the correct type.
        /// - `a_selector` must be a valid selector.
        /// - `an_object` should be of the correct type.
        #[unsafe(method(addObserver:selector:name:object:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addObserver_selector_name_object(
            &self,
            observer: &AnyObject,
            a_selector: Sel,
            a_name: Option<&NSNotificationName>,
            an_object: Option<&AnyObject>,
        );

        #[unsafe(method(postNotification:))]
        #[unsafe(method_family = none)]
        pub fn postNotification(&self, notification: &NSNotification);

        #[cfg(feature = "NSString")]
        /// # Safety
        ///
        /// `an_object` should be of the correct type.
        #[unsafe(method(postNotificationName:object:))]
        #[unsafe(method_family = none)]
        pub unsafe fn postNotificationName_object(
            &self,
            a_name: &NSNotificationName,
            an_object: Option<&AnyObject>,
        );

        #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
        /// # Safety
        ///
        /// - `an_object` should be of the correct type.
        /// - `a_user_info` generic should be of the correct type.
        #[unsafe(method(postNotificationName:object:userInfo:))]
        #[unsafe(method_family = none)]
        pub unsafe fn postNotificationName_object_userInfo(
            &self,
            a_name: &NSNotificationName,
            an_object: Option<&AnyObject>,
            a_user_info: Option<&NSDictionary>,
        );

        /// # Safety
        ///
        /// `observer` should be of the correct type.
        #[unsafe(method(removeObserver:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeObserver(&self, observer: &AnyObject);

        #[cfg(feature = "NSString")]
        /// # Safety
        ///
        /// - `observer` should be of the correct type.
        /// - `an_object` should be of the correct type.
        #[unsafe(method(removeObserver:name:object:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeObserver_name_object(
            &self,
            observer: &AnyObject,
            a_name: Option<&NSNotificationName>,
            an_object: Option<&AnyObject>,
        );

        #[cfg(all(feature = "NSOperation", feature = "NSString", feature = "block2"))]
        /// # Safety
        ///
        /// - `obj` should be of the correct type.
        /// - `queue` possibly has additional threading requirements.
        /// - `block` block must be sendable.
        #[unsafe(method(addObserverForName:object:queue:usingBlock:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addObserverForName_object_queue_usingBlock(
            &self,
            name: Option<&NSNotificationName>,
            obj: Option<&AnyObject>,
            queue: Option<&NSOperationQueue>,
            block: &block2::DynBlock<dyn Fn(NonNull<NSNotification>)>,
        ) -> Retained<ProtocolObject<dyn NSObjectProtocol>>;
    );
}

/// Methods declared on superclass `NSObject`.
impl NSNotificationCenter {
    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 NSNotificationCenter {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}