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        ///
53        /// # Safety
54        ///
55        /// `observable_class` probably has further requirements.
56        #[unsafe(method(initWithObservableClass:))]
57        #[unsafe(method_family = init)]
58        pub unsafe fn initWithObservableClass(
59            this: Allocated<Self>,
60            observable_class: &AnyClass,
61        ) -> Retained<Self>;
62
63        #[unsafe(method(init))]
64        #[unsafe(method_family = init)]
65        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
66
67        #[unsafe(method(new))]
68        #[unsafe(method_family = new)]
69        pub unsafe fn new() -> Retained<Self>;
70
71        #[cfg(all(feature = "NSKeyValueObserving", feature = "NSString"))]
72        /// Add a new observer to the collection.
73        ///
74        /// This method works like `-[NSObject addObserver: forKey: options: context:]`,
75        /// but observations on nested and computed properties are disallowed. Observers
76        /// are not registered until `setSharedObservers` is called on the observable.
77        ///
78        /// - Parameter observer: The observer object to register for KVO notifications.
79        /// The observer must implement the key-value observing method ``observeValue:
80        /// forKeyPath: of: change: context:``
81        /// - Parameter key: key of the property being observed. This cannot be a nested
82        /// key path or a computed property
83        /// - Parameter options: A combination of NSKeyValueObservingOptions values that
84        /// specify what is included in observation notifications. For possible values
85        /// see NSKeyValueObservingOptions.
86        /// - Parameter context: Arbitrary data which is passed to the observer object
87        ///
88        /// # Safety
89        ///
90        /// - `observer` should be of the correct type.
91        /// - `context` must be a valid pointer or null.
92        #[unsafe(method(addSharedObserver:forKey:options:context:))]
93        #[unsafe(method_family = none)]
94        pub unsafe fn addSharedObserver_forKey_options_context(
95            &self,
96            observer: &NSObject,
97            key: &NSString,
98            options: NSKeyValueObservingOptions,
99            context: *mut c_void,
100        );
101
102        #[cfg(all(feature = "NSKeyValueObserving", feature = "NSString"))]
103        /// # Safety
104        ///
105        /// - `observer` should be of the correct type.
106        /// - `context` must be a valid pointer or null.
107        #[unsafe(method(addObserver:forKeyPath:options:context:))]
108        #[unsafe(method_family = none)]
109        pub unsafe fn addObserver_forKeyPath_options_context(
110            &self,
111            observer: &NSObject,
112            key_path: &NSString,
113            options: NSKeyValueObservingOptions,
114            context: *mut c_void,
115        );
116
117        /// A momentary snapshot of all observers added to the collection thus far, that
118        /// can be assigned to an observable using ``-[NSObject setSharedObservers:]``
119        #[unsafe(method(snapshot))]
120        #[unsafe(method_family = none)]
121        pub fn snapshot(&self) -> Retained<NSKeyValueSharedObserversSnapshot>;
122    );
123}
124
125mod private_NSObjectNSKeyValueSharedObserverRegistration {
126    pub trait Sealed {}
127}
128
129/// Category "NSKeyValueSharedObserverRegistration" on [`NSObject`].
130#[doc(alias = "NSKeyValueSharedObserverRegistration")]
131pub unsafe trait NSObjectNSKeyValueSharedObserverRegistration:
132    ClassType + Sized + private_NSObjectNSKeyValueSharedObserverRegistration::Sealed
133{
134    extern_methods!(
135        /// Register shared observations.
136        ///
137        /// A shared observation collection might be shared between multiple observables
138        /// to minimise registration work. Shared observers remain registered throughout
139        /// the object's lifetime and do not need to be removed using `removeObserver:`.
140        ///
141        /// An observable may only have one set of shared observations. Subsequent calls
142        /// to this method will replace existing shared observations.
143        ///
144        /// - Parameter sharedObservers: shared observer collection that was initialized
145        /// with the class of this object
146        /// - Invariant: `sharedObserers` was initialized with the class of this object
147        /// - Throws: Exception if the class of the receiving observable object does not
148        /// match the class with which `sharedObserers` was initialized.
149        #[unsafe(method(setSharedObservers:))]
150        #[unsafe(method_family = none)]
151        fn setSharedObservers(&self, shared_observers: Option<&NSKeyValueSharedObserversSnapshot>);
152    );
153}
154
155impl private_NSObjectNSKeyValueSharedObserverRegistration::Sealed for NSObject {}
156unsafe impl NSObjectNSKeyValueSharedObserverRegistration for NSObject {}