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