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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//! 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 objc2_foundation::*;
use crate::*;
extern_protocol!(
/// [Apple's documentation](https://developer.apple.com/documentation/classkit/clsdatastoredelegate?language=objc)
pub unsafe trait CLSDataStoreDelegate: NSObjectProtocol {
#[cfg(all(feature = "CLSContext", feature = "CLSObject"))]
/// Implement to return a new context with the supplied identifier as a child of the parent context.
///
/// This method is invoked for missing contexts in:
///
/// ```text
/// -[CLSDataStore contextsMatchingIdentifierPath:completion:]
/// ```
///
/// and
///
/// ```text
/// -[CLSContext descendantMatchingIdentifierPath:completion:]
/// ```
///
/// It will be called successively for each identifier in the path that is not found. This helps centralize context creation in one place.
///
/// Note: New contexts returned in this method are automatically saved.
///
///
/// Parameter `identifier`: Identifier for the new context.
///
/// Parameter `parentContext`: Parent of the new context.
///
/// Parameter `parentIdentifierPath`: Ordered list of identifiers leading to the parent context.
///
///
/// Returns: The new context for the supplied identifier. The new context is automatically saved.
#[unsafe(method(createContextForIdentifier:parentContext:parentIdentifierPath:))]
#[unsafe(method_family = none)]
unsafe fn createContextForIdentifier_parentContext_parentIdentifierPath(
&self,
identifier: &NSString,
parent_context: &CLSContext,
parent_identifier_path: &NSArray<NSString>,
) -> Option<Retained<CLSContext>>;
}
);
extern_class!(
/// The data store maintains and syncs your app's contexts.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/classkit/clsdatastore?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct CLSDataStore;
);
extern_conformance!(
unsafe impl NSObjectProtocol for CLSDataStore {}
);
impl CLSDataStore {
extern_methods!(
/// The data store provides read/write access to your app's ClassKit data.
///
/// Data written to the data store is automatically synced via iCloud across the user's devices.
#[unsafe(method(shared))]
#[unsafe(method_family = none)]
pub unsafe fn shared() -> Retained<CLSDataStore>;
#[cfg(all(feature = "CLSContext", feature = "CLSObject"))]
/// Fetch the top level context for the current app.
///
/// The main context is automatically created. Add child contexts to this context to persist them in the data store.
#[unsafe(method(mainAppContext))]
#[unsafe(method_family = none)]
pub unsafe fn mainAppContext(&self) -> Retained<CLSContext>;
#[cfg(all(feature = "CLSContext", feature = "CLSObject"))]
/// Returns the context that is currently active. If no context is active, this will return nil.
#[unsafe(method(activeContext))]
#[unsafe(method_family = none)]
pub unsafe fn activeContext(&self) -> Option<Retained<CLSContext>>;
#[cfg(all(feature = "CLSActivity", feature = "CLSObject"))]
/// Returns the most recently started activity that is running.
#[unsafe(method(runningActivity))]
#[unsafe(method_family = none)]
pub unsafe fn runningActivity(&self) -> Option<Retained<CLSActivity>>;
/// The data store delegate allows for easy population of the app's context hierarchy.
#[unsafe(method(delegate))]
#[unsafe(method_family = none)]
pub unsafe fn delegate(&self)
-> Option<Retained<ProtocolObject<dyn CLSDataStoreDelegate>>>;
/// Setter for [`delegate`][Self::delegate].
///
/// This is a [weak property][objc2::topics::weak_property].
#[unsafe(method(setDelegate:))]
#[unsafe(method_family = none)]
pub unsafe fn setDelegate(
&self,
delegate: Option<&ProtocolObject<dyn CLSDataStoreDelegate>>,
);
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[cfg(feature = "block2")]
/// Save changes made in the data store.
///
/// Save new/modified/removed contexts, activities, etc. to the local store. In case of an error -[NSError userInfo] will contain the object that caused the error under the CLSErrorObjectKey..
#[unsafe(method(saveWithCompletion:))]
#[unsafe(method_family = none)]
pub unsafe fn saveWithCompletion(
&self,
completion: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
);
/// Complete all assigned actvities.
///
/// Marks all of the currently active assigned activities for this contextPath as complete.
#[unsafe(method(completeAllAssignedActivitiesMatching:))]
#[unsafe(method_family = none)]
pub unsafe fn completeAllAssignedActivitiesMatching(
&self,
context_path: &NSArray<NSString>,
);
);
}
/// Contexts.
impl CLSDataStore {
extern_methods!(
#[cfg(all(feature = "CLSContext", feature = "CLSObject", feature = "block2"))]
/// Fetch contexts matching a predicate.
///
/// For example: NSPredicate
/// <topic
/// == CLSContextTopicMath AND parent == someContext>. Completion block may be called on a background thread.
#[unsafe(method(contextsMatchingPredicate:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn contextsMatchingPredicate_completion(
&self,
predicate: &NSPredicate,
completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<CLSContext>>, *mut NSError)>,
);
#[cfg(all(feature = "CLSContext", feature = "CLSObject", feature = "block2"))]
/// Returns contexts matching a set of identifiers where each identifier is the parent of the following identifier.
///
/// For example:
/// `@["math-game",``"level1"]`returns two contexts where
/// _math-game_is the parent of
/// _level1._If there are any missing contexts, they will be filled in by calling the following method on the data store's delegate:
///
/// ```text
/// -[CLSDataStoreDelegate createContextForIdentifier:parentContext:parentIdentifierPath:]
/// ```
///
/// If the dataStore does not have a delegate and there are missing contexts then an incomplete list of contexts will be passed to the completion handler. Completion block may be called on a background thread.
#[unsafe(method(contextsMatchingIdentifierPath:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn contextsMatchingIdentifierPath_completion(
&self,
identifier_path: &NSArray<NSString>,
completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<CLSContext>>, *mut NSError)>,
);
#[cfg(all(feature = "CLSContext", feature = "CLSObject"))]
/// Mark a context for removal.
///
/// Save to commit removal. Removal cascades and deletes all descendants.
#[unsafe(method(removeContext:))]
#[unsafe(method_family = none)]
pub unsafe fn removeContext(&self, context: &CLSContext);
#[cfg(all(feature = "CLSActivity", feature = "CLSObject", feature = "block2"))]
/// Implement to fetch the current CLSActivity instance for your document to add progress to.
///
/// Gets the currently CLSActivity for the file. If no current activity exists, one will be created for you.
///
/// Parameter `url`: File url for the document.
#[unsafe(method(fetchActivityForURL:completion:))]
#[unsafe(method_family = none)]
pub unsafe fn fetchActivityForURL_completion(
&self,
url: &NSURL,
completion: &block2::DynBlock<dyn Fn(*mut CLSActivity, *mut NSError)>,
);
);
}