objc2_foundation/generated/
NSKeyValueSharedObservers.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9extern_class!(
10    /// A collection of key-value observations which may be registered with multiple
11    /// observable objects. Create using ``-[NSKeyValueSharedObservers snapshot]``
12    ///
13    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nskeyvaluesharedobserverssnapshot?language=objc)
14    #[unsafe(super(NSObject))]
15    #[derive(Debug, PartialEq, Eq, Hash)]
16    pub struct NSKeyValueSharedObserversSnapshot;
17);
18
19extern_conformance!(
20    unsafe impl NSObjectProtocol for NSKeyValueSharedObserversSnapshot {}
21);
22
23impl NSKeyValueSharedObserversSnapshot {
24    extern_methods!(
25        #[unsafe(method(init))]
26        #[unsafe(method_family = init)]
27        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
28
29        #[unsafe(method(new))]
30        #[unsafe(method_family = new)]
31        pub unsafe fn new() -> Retained<Self>;
32    );
33}
34
35extern_class!(
36    /// A collection of key-value observations which may be registered with multiple
37    /// observable objects
38    ///
39    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nskeyvaluesharedobservers?language=objc)
40    #[unsafe(super(NSObject))]
41    #[derive(Debug, PartialEq, Eq, Hash)]
42    pub struct NSKeyValueSharedObservers;
43);
44
45extern_conformance!(
46    unsafe impl NSObjectProtocol for NSKeyValueSharedObservers {}
47);
48
49impl NSKeyValueSharedObservers {
50    extern_methods!(
51        /// A new collection of observables for an observable object of the given class
52        #[unsafe(method(initWithObservableClass:))]
53        #[unsafe(method_family = init)]
54        pub unsafe fn initWithObservableClass(
55            this: Allocated<Self>,
56            observable_class: &AnyClass,
57        ) -> Retained<Self>;
58
59        #[unsafe(method(init))]
60        #[unsafe(method_family = init)]
61        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
62
63        #[unsafe(method(new))]
64        #[unsafe(method_family = new)]
65        pub unsafe fn new() -> Retained<Self>;
66
67        #[cfg(all(feature = "NSKeyValueObserving", feature = "NSString"))]
68        /// Add a new observer to the collection.
69        ///
70        /// This method works like `-[NSObject addObserver: forKey: options: context:]`,
71        /// but observations on nested and computed properties are disallowed. Observers
72        /// are not registered until `setSharedObservers` is called on the observable.
73        ///
74        /// - Parameter observer: The observer object to register for KVO notifications.
75        /// The observer must implement the key-value observing method ``observeValue:
76        /// forKeyPath: of: change: context:``
77        /// - Parameter key: key of the property being observed. This cannot be a nested
78        /// key path or a computed property
79        /// - Parameter options: A combination of NSKeyValueObservingOptions values that
80        /// specify what is included in observation notifications. For possible values
81        /// see NSKeyValueObservingOptions.
82        /// - Parameter context: Arbitrary data which is passed to the observer object
83        #[unsafe(method(addSharedObserver:forKey:options:context:))]
84        #[unsafe(method_family = none)]
85        pub unsafe fn addSharedObserver_forKey_options_context(
86            &self,
87            observer: &NSObject,
88            key: &NSString,
89            options: NSKeyValueObservingOptions,
90            context: *mut c_void,
91        );
92
93        #[cfg(all(feature = "NSKeyValueObserving", feature = "NSString"))]
94        #[unsafe(method(addObserver:forKeyPath:options:context:))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn addObserver_forKeyPath_options_context(
97            &self,
98            observer: &NSObject,
99            key_path: &NSString,
100            options: NSKeyValueObservingOptions,
101            context: *mut c_void,
102        );
103
104        /// A momentary snapshot of all observers added to the collection thus far, that
105        /// can be assigned to an observable using ``-[NSObject setSharedObservers:]``
106        #[unsafe(method(snapshot))]
107        #[unsafe(method_family = none)]
108        pub unsafe fn snapshot(&self) -> Retained<NSKeyValueSharedObserversSnapshot>;
109    );
110}
111
112mod private_NSObjectNSKeyValueSharedObserverRegistration {
113    pub trait Sealed {}
114}
115
116/// Category "NSKeyValueSharedObserverRegistration" on [`NSObject`].
117#[doc(alias = "NSKeyValueSharedObserverRegistration")]
118pub unsafe trait NSObjectNSKeyValueSharedObserverRegistration:
119    ClassType + Sized + private_NSObjectNSKeyValueSharedObserverRegistration::Sealed
120{
121    extern_methods!(
122        /// Register shared observations.
123        ///
124        /// A shared observation collection might be shared between multiple observables
125        /// to minimise registration work. Shared observers remain registered throughout
126        /// the object's lifetime and do not need to be removed using `removeObserver:`.
127        ///
128        /// An observable may only have one set of shared observations. Subsequent calls
129        /// to this method will replace existing shared observations.
130        ///
131        /// - Parameter sharedObservers: shared observer collection that was initialized
132        /// with the class of this object
133        /// - Invariant: `sharedObserers` was initialized with the class of this object
134        /// - Throws: Exception if the class of the receiving observable object does not
135        /// match the class with which `sharedObserers` was initialized.
136        #[unsafe(method(setSharedObservers:))]
137        #[unsafe(method_family = none)]
138        unsafe fn setSharedObservers(
139            &self,
140            shared_observers: Option<&NSKeyValueSharedObserversSnapshot>,
141        );
142    );
143}
144
145impl private_NSObjectNSKeyValueSharedObserverRegistration::Sealed for NSObject {}
146unsafe impl NSObjectNSKeyValueSharedObserverRegistration for NSObject {}