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