objc2_class_kit/generated/
CLSDataStore.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_protocol!(
11    /// [Apple's documentation](https://developer.apple.com/documentation/classkit/clsdatastoredelegate?language=objc)
12    pub unsafe trait CLSDataStoreDelegate: NSObjectProtocol {
13        #[cfg(all(feature = "CLSContext", feature = "CLSObject"))]
14        /// Implement to return a new context with the supplied identifier as a child of the parent context.
15        ///
16        /// This method is invoked for missing contexts in:
17        ///
18        /// ```text
19        ///  -[CLSDataStore contextsMatchingIdentifierPath:completion:]
20        /// ```
21        ///
22        /// and
23        ///
24        /// ```text
25        ///  -[CLSContext descendantMatchingIdentifierPath:completion:]
26        /// ```
27        ///
28        /// It will be called successively for each identifier in the path that is not found. This helps centralize context creation in one place.
29        ///
30        /// Note: New contexts returned in this method are automatically saved.
31        ///
32        ///
33        /// Parameter `identifier`: Identifier for the new context.
34        ///
35        /// Parameter `parentContext`: Parent of the new context.
36        ///
37        /// Parameter `parentIdentifierPath`: Ordered list of identifiers leading to the parent context.
38        ///
39        ///
40        /// Returns: The new context for the supplied identifier. The new context is automatically saved.
41        #[unsafe(method(createContextForIdentifier:parentContext:parentIdentifierPath:))]
42        #[unsafe(method_family = none)]
43        unsafe fn createContextForIdentifier_parentContext_parentIdentifierPath(
44            &self,
45            identifier: &NSString,
46            parent_context: &CLSContext,
47            parent_identifier_path: &NSArray<NSString>,
48        ) -> Option<Retained<CLSContext>>;
49    }
50);
51
52extern_class!(
53    /// The data store maintains and syncs your app's contexts.
54    ///
55    /// See also [Apple's documentation](https://developer.apple.com/documentation/classkit/clsdatastore?language=objc)
56    #[unsafe(super(NSObject))]
57    #[derive(Debug, PartialEq, Eq, Hash)]
58    pub struct CLSDataStore;
59);
60
61extern_conformance!(
62    unsafe impl NSObjectProtocol for CLSDataStore {}
63);
64
65impl CLSDataStore {
66    extern_methods!(
67        /// The data store provides read/write access to your app's ClassKit data.
68        ///
69        /// Data written to the data store is automatically synced via iCloud across the user's devices.
70        #[unsafe(method(shared))]
71        #[unsafe(method_family = none)]
72        pub unsafe fn shared() -> Retained<CLSDataStore>;
73
74        #[cfg(all(feature = "CLSContext", feature = "CLSObject"))]
75        /// Fetch the top level context for the current app.
76        ///
77        /// The main context is automatically created. Add child contexts to this context to persist them in the data store.
78        #[unsafe(method(mainAppContext))]
79        #[unsafe(method_family = none)]
80        pub unsafe fn mainAppContext(&self) -> Retained<CLSContext>;
81
82        #[cfg(all(feature = "CLSContext", feature = "CLSObject"))]
83        /// Returns the context that is currently active. If no context is active, this will return nil.
84        #[unsafe(method(activeContext))]
85        #[unsafe(method_family = none)]
86        pub unsafe fn activeContext(&self) -> Option<Retained<CLSContext>>;
87
88        #[cfg(all(feature = "CLSActivity", feature = "CLSObject"))]
89        /// Returns the most recently started activity that is running.
90        #[unsafe(method(runningActivity))]
91        #[unsafe(method_family = none)]
92        pub unsafe fn runningActivity(&self) -> Option<Retained<CLSActivity>>;
93
94        /// The data store delegate allows for easy population of the app's context hierarchy.
95        #[unsafe(method(delegate))]
96        #[unsafe(method_family = none)]
97        pub unsafe fn delegate(&self)
98            -> Option<Retained<ProtocolObject<dyn CLSDataStoreDelegate>>>;
99
100        /// This is a [weak property][objc2::topics::weak_property].
101        /// Setter for [`delegate`][Self::delegate].
102        #[unsafe(method(setDelegate:))]
103        #[unsafe(method_family = none)]
104        pub unsafe fn setDelegate(
105            &self,
106            delegate: Option<&ProtocolObject<dyn CLSDataStoreDelegate>>,
107        );
108
109        #[unsafe(method(new))]
110        #[unsafe(method_family = new)]
111        pub unsafe fn new() -> Retained<Self>;
112
113        #[unsafe(method(init))]
114        #[unsafe(method_family = init)]
115        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
116
117        #[cfg(feature = "block2")]
118        /// Save changes made in the data store.
119        ///
120        /// 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..
121        #[unsafe(method(saveWithCompletion:))]
122        #[unsafe(method_family = none)]
123        pub unsafe fn saveWithCompletion(
124            &self,
125            completion: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
126        );
127
128        /// Complete all assigned actvities.
129        ///
130        /// Marks all of the currently active assigned activities for this contextPath as complete.
131        #[unsafe(method(completeAllAssignedActivitiesMatching:))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn completeAllAssignedActivitiesMatching(
134            &self,
135            context_path: &NSArray<NSString>,
136        );
137    );
138}
139
140/// Contexts.
141impl CLSDataStore {
142    extern_methods!(
143        #[cfg(all(feature = "CLSContext", feature = "CLSObject", feature = "block2"))]
144        /// Fetch contexts matching a predicate.
145        ///
146        /// For example: NSPredicate
147        /// <topic
148        /// == CLSContextTopicMath AND parent == someContext>.  Completion block may be called on a background thread.
149        #[unsafe(method(contextsMatchingPredicate:completion:))]
150        #[unsafe(method_family = none)]
151        pub unsafe fn contextsMatchingPredicate_completion(
152            &self,
153            predicate: &NSPredicate,
154            completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<CLSContext>>, *mut NSError)>,
155        );
156
157        #[cfg(all(feature = "CLSContext", feature = "CLSObject", feature = "block2"))]
158        /// Returns contexts matching a set of identifiers where each identifier is the parent of the following identifier.
159        ///
160        /// For example:
161        /// `@["math-game",``"level1"]`returns two contexts where
162        /// _math-game_is the parent of
163        /// _level1._If there are any missing contexts, they will be filled in by calling the following method on the data store's delegate:
164        ///
165        /// ```text
166        ///  -[CLSDataStoreDelegate createContextForIdentifier:parentContext:parentIdentifierPath:]
167        /// ```
168        ///
169        /// 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.
170        #[unsafe(method(contextsMatchingIdentifierPath:completion:))]
171        #[unsafe(method_family = none)]
172        pub unsafe fn contextsMatchingIdentifierPath_completion(
173            &self,
174            identifier_path: &NSArray<NSString>,
175            completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<CLSContext>>, *mut NSError)>,
176        );
177
178        #[cfg(all(feature = "CLSContext", feature = "CLSObject"))]
179        /// Mark a context for removal.
180        ///
181        /// Save to commit removal. Removal cascades and deletes all descendants.
182        #[unsafe(method(removeContext:))]
183        #[unsafe(method_family = none)]
184        pub unsafe fn removeContext(&self, context: &CLSContext);
185
186        #[cfg(all(feature = "CLSActivity", feature = "CLSObject", feature = "block2"))]
187        /// Implement to fetch the current CLSActivity instance for your document to add progress to.
188        ///
189        /// Gets the currently CLSActivity for the file. If no current activity exists, one will be created for you.
190        ///
191        /// Parameter `url`: File url for the document.
192        #[unsafe(method(fetchActivityForURL:completion:))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn fetchActivityForURL_completion(
195            &self,
196            url: &NSURL,
197            completion: &block2::DynBlock<dyn Fn(*mut CLSActivity, *mut NSError)>,
198        );
199    );
200}