objc2-class-kit 0.3.2

Bindings to the ClassKit framework
Documentation
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
//! 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::*;
#[cfg(feature = "objc2-core-graphics")]
use objc2_core_graphics::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontexttype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CLSContextType(pub NSInteger);
impl CLSContextType {
    #[doc(alias = "CLSContextTypeNone")]
    pub const None: Self = Self(0);
    #[doc(alias = "CLSContextTypeApp")]
    pub const App: Self = Self(1);
    #[doc(alias = "CLSContextTypeChapter")]
    pub const Chapter: Self = Self(2);
    #[doc(alias = "CLSContextTypeSection")]
    pub const Section: Self = Self(3);
    #[doc(alias = "CLSContextTypeLevel")]
    pub const Level: Self = Self(4);
    #[doc(alias = "CLSContextTypePage")]
    pub const Page: Self = Self(5);
    #[doc(alias = "CLSContextTypeTask")]
    pub const Task: Self = Self(6);
    #[doc(alias = "CLSContextTypeChallenge")]
    pub const Challenge: Self = Self(7);
    #[doc(alias = "CLSContextTypeQuiz")]
    pub const Quiz: Self = Self(8);
    #[doc(alias = "CLSContextTypeExercise")]
    pub const Exercise: Self = Self(9);
    #[doc(alias = "CLSContextTypeLesson")]
    pub const Lesson: Self = Self(10);
    #[doc(alias = "CLSContextTypeBook")]
    pub const Book: Self = Self(11);
    #[doc(alias = "CLSContextTypeGame")]
    pub const Game: Self = Self(12);
    #[doc(alias = "CLSContextTypeDocument")]
    pub const Document: Self = Self(13);
    #[doc(alias = "CLSContextTypeAudio")]
    pub const Audio: Self = Self(14);
    #[doc(alias = "CLSContextTypeVideo")]
    pub const Video: Self = Self(15);
    #[doc(alias = "CLSContextTypeCourse")]
    pub const Course: Self = Self(16);
    #[doc(alias = "CLSContextTypeCustom")]
    pub const Custom: Self = Self(17);
}

unsafe impl Encode for CLSContextType {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for CLSContextType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontexttopic?language=objc)
// NS_TYPED_ENUM
pub type CLSContextTopic = NSString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontexttopicmath?language=objc)
    pub static CLSContextTopicMath: &'static CLSContextTopic;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontexttopicscience?language=objc)
    pub static CLSContextTopicScience: &'static CLSContextTopic;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontexttopicliteracyandwriting?language=objc)
    pub static CLSContextTopicLiteracyAndWriting: &'static CLSContextTopic;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontexttopicworldlanguage?language=objc)
    pub static CLSContextTopicWorldLanguage: &'static CLSContextTopic;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontexttopicsocialscience?language=objc)
    pub static CLSContextTopicSocialScience: &'static CLSContextTopic;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontexttopiccomputerscienceandengineering?language=objc)
    pub static CLSContextTopicComputerScienceAndEngineering: &'static CLSContextTopic;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontexttopicartsandmusic?language=objc)
    pub static CLSContextTopicArtsAndMusic: &'static CLSContextTopic;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontexttopichealthandfitness?language=objc)
    pub static CLSContextTopicHealthAndFitness: &'static CLSContextTopic;
}

extern_class!(
    /// Contexts represent activities, documents, and areas within your app.
    ///
    /// Contexts have two major components.
    ///
    /// (1) Child contexts, used to model your app hierarchy.
    /// (2) Activity, holds user generated data that pertains to this context.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/classkit/clscontext?language=objc)
    #[unsafe(super(CLSObject, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "CLSObject")]
    pub struct CLSContext;
);

#[cfg(feature = "CLSObject")]
extern_conformance!(
    unsafe impl NSCoding for CLSContext {}
);

#[cfg(feature = "CLSObject")]
extern_conformance!(
    unsafe impl NSObjectProtocol for CLSContext {}
);

#[cfg(feature = "CLSObject")]
extern_conformance!(
    unsafe impl NSSecureCoding for CLSContext {}
);

#[cfg(feature = "CLSObject")]
impl CLSContext {
    extern_methods!(
        #[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>;

        /// Context identifier path of this context.
        ///
        /// The identifier path starts with the main app context object and finishes with the identifier of this context. This is the identifier path that one would use in
        ///
        /// ```text
        ///  -[CLSDataStore contextsMatchingIdintifierPath:completion:]
        /// ```
        ///
        /// to find `this' context.
        #[unsafe(method(identifierPath))]
        #[unsafe(method_family = none)]
        pub unsafe fn identifierPath(&self) -> Retained<NSArray<NSString>>;

        /// App-assigned identifier. This identifier should work across users and devices and be unique with regards to its siblings within its parent.
        ///
        /// The identifier could be used to embed information later used for deep linking. For example:
        /// _hydrogen-element,_or
        /// _chapter-1._
        #[unsafe(method(identifier))]
        #[unsafe(method_family = none)]
        pub unsafe fn identifier(&self) -> Retained<NSString>;

        /// Alternative deep link URL using universal links.
        ///
        /// If your app supports universal links, you can supply them here to link the content this context represents.
        #[unsafe(method(universalLinkURL))]
        #[unsafe(method_family = none)]
        pub unsafe fn universalLinkURL(&self) -> Option<Retained<NSURL>>;

        /// Setter for [`universalLinkURL`][Self::universalLinkURL].
        #[unsafe(method(setUniversalLinkURL:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setUniversalLinkURL(&self, universal_link_url: Option<&NSURL>);

        /// Type of this context
        ///
        /// The type that best describes this context.
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        pub unsafe fn r#type(&self) -> CLSContextType;

        /// An optional user-visible name for the context if its type is CLSContextTypeCustom.
        ///
        /// This property is relevant only if the type is CLSContextTypeCustom. This string should be localized. If this property is not set for a context of type CLSContextTypeCustom, Schoolwork app will use a default localized string ‘Custom’ as the name of the activity representing this context.
        #[unsafe(method(customTypeName))]
        #[unsafe(method_family = none)]
        pub unsafe fn customTypeName(&self) -> Option<Retained<NSString>>;

        /// Setter for [`customTypeName`][Self::customTypeName].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setCustomTypeName:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCustomTypeName(&self, custom_type_name: Option<&NSString>);

        /// Title of this context.
        ///
        /// For example:
        /// _Level_1
        /// _._
        #[unsafe(method(title))]
        #[unsafe(method_family = none)]
        pub unsafe fn title(&self) -> Retained<NSString>;

        /// Setter for [`title`][Self::title].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setTitle:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTitle(&self, title: &NSString);

        /// The displayOrder is by default sorted ascending.
        ///
        /// Set the displayOrder if you want your contexts to be displayed in a particular order. The sort key is used as a way to sort sibling contexts in a particular order.
        #[unsafe(method(displayOrder))]
        #[unsafe(method_family = none)]
        pub unsafe fn displayOrder(&self) -> NSInteger;

        /// Setter for [`displayOrder`][Self::displayOrder].
        #[unsafe(method(setDisplayOrder:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDisplayOrder(&self, display_order: NSInteger);

        /// Topic associated with this context.
        ///
        /// See above for valid, predefined topics.
        #[unsafe(method(topic))]
        #[unsafe(method_family = none)]
        pub unsafe fn topic(&self) -> Option<Retained<CLSContextTopic>>;

        /// Setter for [`topic`][Self::topic].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setTopic:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTopic(&self, topic: Option<&CLSContextTopic>);

        /// This property is true if the context can be assigned as an activity.
        ///
        /// The default value of this property is true. This should be set to false for a context that is used as a container for other contexts, but by itself, is not an assignable activity.
        #[unsafe(method(isAssignable))]
        #[unsafe(method_family = none)]
        pub unsafe fn isAssignable(&self) -> bool;

        /// Setter for [`isAssignable`][Self::isAssignable].
        #[unsafe(method(setAssignable:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAssignable(&self, assignable: bool);

        /// Suggested age range of students, expressed in years, for whom this context is suitable. This information is intended to help teachers to choose age-appropriate activities for their students.
        ///
        /// The default value is [0, NSIntegerMax - 1]. This is
        /// _NSRange(0...Int.max-1)_in
        /// _Swift_or
        /// _NSMakeRange(0,NSIntegerMax)_in
        /// _Objective-C._Set the lower bound to 0 to specify no minimum age limit and set the upper bound to NSIntegerMax - 1 to specify no maximum age limit.
        #[unsafe(method(suggestedAge))]
        #[unsafe(method_family = none)]
        pub unsafe fn suggestedAge(&self) -> NSRange;

        /// Setter for [`suggestedAge`][Self::suggestedAge].
        #[unsafe(method(setSuggestedAge:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSuggestedAge(&self, suggested_age: NSRange);

        /// Suggested time range, expressed in minutes, to complete the activity. This information will help teachers as they choose activities for their students.
        ///
        /// The default value is [0, NSIntegerMax - 1]. This is
        /// _NSRange(0...Int.max-1)_in
        /// _Swift_or
        /// _NSMakeRange(0,NSIntegerMax)_in
        /// _Objective-C._Set the lower bound value to 0 to specify no minimum time limit and set the upper bound to NSIntegerMax - 1 to specify no maximum time limit.
        #[unsafe(method(suggestedCompletionTime))]
        #[unsafe(method_family = none)]
        pub unsafe fn suggestedCompletionTime(&self) -> NSRange;

        /// Setter for [`suggestedCompletionTime`][Self::suggestedCompletionTime].
        #[unsafe(method(setSuggestedCompletionTime:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSuggestedCompletionTime(&self, suggested_completion_time: NSRange);

        #[cfg(feature = "CLSProgressReportingCapability")]
        /// Specifies progress reporting capablities of the app for this context.
        ///
        /// This information is intended to help teachers as they choose activities for their students. By default a CLSContext will have one CLSProgressReportingCapability instance of kind CLSProgressReportingCapabilityKindDuration. More progress reporting capabilities can be specified via '-addProgressReportingCapabilities:' to customize this set.
        #[unsafe(method(progressReportingCapabilities))]
        #[unsafe(method_family = none)]
        pub unsafe fn progressReportingCapabilities(
            &self,
        ) -> Retained<NSSet<CLSProgressReportingCapability>>;

        /// An optional user-visible summary describing the context limited to 4000 characters in length.
        ///
        /// This may be used to provide information about the types of activities available under a given context or the context itself. This string should be localized.
        #[unsafe(method(summary))]
        #[unsafe(method_family = none)]
        pub unsafe fn summary(&self) -> Option<Retained<NSString>>;

        /// Setter for [`summary`][Self::summary].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setSummary:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSummary(&self, summary: Option<&NSString>);

        #[cfg(feature = "objc2-core-graphics")]
        /// An optional thumbnail image associated with the context.
        ///
        /// The size of this image should be equal to or larger than 80x80 pixels and equal to or smaller than 330x330 pixels. Images larger than 330x330 pixels will be scaled down. Images with both dimensions smaller than 80x80 pixels will not be accepted.
        #[unsafe(method(thumbnail))]
        #[unsafe(method_family = none)]
        pub unsafe fn thumbnail(&self) -> Option<Retained<CGImage>>;

        #[cfg(feature = "objc2-core-graphics")]
        /// Setter for [`thumbnail`][Self::thumbnail].
        #[unsafe(method(setThumbnail:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setThumbnail(&self, thumbnail: Option<&CGImage>);

        /// Initialize and configure the type of content this context represents.
        ///
        /// Parameter `identifier`: App-assigned identifier for this context. 256 characters max length.
        ///
        /// Parameter `type`: The type of content this context represents.
        ///
        /// Parameter `title`: Title for what this context represents. 256 characters max length.
        #[unsafe(method(initWithType:identifier:title:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithType_identifier_title(
            this: Allocated<Self>,
            r#type: CLSContextType,
            identifier: &NSString,
            title: &NSString,
        ) -> Retained<Self>;

        /// Returns true if self is the active context.
        #[unsafe(method(isActive))]
        #[unsafe(method_family = none)]
        pub unsafe fn isActive(&self) -> bool;

        /// Marks contexts as active.
        ///
        /// If a context is already active, it will remain active. If another context is active, the other will resign active before this one becomes active.
        #[unsafe(method(becomeActive))]
        #[unsafe(method_family = none)]
        pub unsafe fn becomeActive(&self);

        /// Resign being active.
        ///
        /// This method does nothing if the reciever of the message is not active.
        #[unsafe(method(resignActive))]
        #[unsafe(method_family = none)]
        pub unsafe fn resignActive(&self);

        /// Sets the type.
        ///
        /// Use this to update a previously saved context.
        #[unsafe(method(setType:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setType(&self, r#type: CLSContextType);

        #[cfg(feature = "CLSProgressReportingCapability")]
        /// Add or replace additional progress reporting capabilities of the app for this context.
        ///
        /// If this parameter contains multiple items with the same value for kind, then one of them will be arbitrarily selected and used. If this parameter contains a capability of kind CLSProgressReportingCapabilityKindDuration, it will be ignored.
        ///
        /// Parameter `capabilities`: Progress reporting capabilities to add or replace existing capabilties.
        #[unsafe(method(addProgressReportingCapabilities:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addProgressReportingCapabilities(
            &self,
            capabilities: &NSSet<CLSProgressReportingCapability>,
        );

        /// Clears CLSProgressReportingCapability objects added to the receiver.
        ///
        /// Removes all capabilities added via '-addProgressReportingCapabilities:'. The context will have the default progress reporting capability of kind CLSProgressReportingCapabilityKindDuration.
        #[unsafe(method(resetProgressReportingCapabilities))]
        #[unsafe(method_family = none)]
        pub unsafe fn resetProgressReportingCapabilities(&self);
    );
}

/// Hierarchy.
#[cfg(feature = "CLSObject")]
impl CLSContext {
    extern_methods!(
        /// Returns the parent of this context.
        #[unsafe(method(parent))]
        #[unsafe(method_family = none)]
        pub unsafe fn parent(&self) -> Option<Retained<CLSContext>>;

        /// Removes this child context from its parent.
        ///
        /// If you remove a context from its parent and do not add it as a child of another context, it will be deleted when you call -save on the dataStore.
        #[unsafe(method(removeFromParent))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeFromParent(&self);

        /// Adds a child context.
        ///
        /// A context can only have a single parent.
        ///
        /// Note: objectID of child context may change after it's been added.
        #[unsafe(method(addChildContext:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addChildContext(&self, child: &CLSContext);

        #[cfg(feature = "block2")]
        /// Returns a descendant of this context matching the context path you provide. Context path must start with an identifier of a child context of the context to which this message is sent.
        ///
        /// If there are any missing contexts, they will be filled in by calling the following method on the context's 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 is called on a background thread.
        #[unsafe(method(descendantMatchingIdentifierPath:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn descendantMatchingIdentifierPath_completion(
            &self,
            identifier_path: &NSArray<NSString>,
            completion: &block2::DynBlock<dyn Fn(*mut CLSContext, *mut NSError)>,
        );

        /// Child contexts that can be navigated to from this context.
        ///
        /// Returns all the child contexts added via
        ///
        /// ```text
        ///  -[CLSContext addNavigationChildContext:]
        /// ```
        #[unsafe(method(navigationChildContexts))]
        #[unsafe(method_family = none)]
        pub unsafe fn navigationChildContexts(&self) -> Retained<NSArray<CLSContext>>;

        /// Adds a child context to specify the user can navigate to the child from this context.
        ///
        /// Used only for presentation purpose. Unlike
        ///
        /// ```text
        ///  -[CLSContext addChildContext:]
        /// ```
        ///
        /// , this method does not affect the identifierPath.
        #[unsafe(method(addNavigationChildContext:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addNavigationChildContext(&self, child: &CLSContext);

        /// Removes the navigation path to the child context from this context.
        ///
        /// Used only for presentation purpose. Unlike
        ///
        /// ```text
        ///  -[CLSContext removeFromParent:]
        /// ```
        ///
        /// , this method does not affect the identiferPath.
        #[unsafe(method(removeNavigationChildContext:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeNavigationChildContext(&self, child: &CLSContext);
    );
}