objc2-foundation 0.3.2

Bindings to the Foundation 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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
//! 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::*;

/// Describes the action an NSCoder should take when it encounters decode failures (e.g. corrupt data) for non-TopLevel decodes.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdecodingfailurepolicy?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSDecodingFailurePolicy(pub NSInteger);
impl NSDecodingFailurePolicy {
    #[doc(alias = "NSDecodingFailurePolicyRaiseException")]
    pub const RaiseException: Self = Self(0);
    #[doc(alias = "NSDecodingFailurePolicySetErrorAndReturn")]
    pub const SetErrorAndReturn: Self = Self(1);
}

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

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

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nscoder?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSCoder;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for NSCoder {}
);

impl NSCoder {
    extern_methods!(
        /// # Safety
        ///
        /// - `type` must be a valid pointer.
        /// - `addr` must be a valid pointer.
        #[unsafe(method(encodeValueOfObjCType:at:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeValueOfObjCType_at(
            &self,
            r#type: NonNull<c_char>,
            addr: NonNull<c_void>,
        );

        #[cfg(feature = "NSData")]
        #[unsafe(method(encodeDataObject:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeDataObject(&self, data: &NSData);

        #[cfg(feature = "NSData")]
        #[unsafe(method(decodeDataObject))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeDataObject(&self) -> Option<Retained<NSData>>;

        /// # Safety
        ///
        /// - `type` must be a valid pointer.
        /// - `data` must be a valid pointer.
        #[unsafe(method(decodeValueOfObjCType:at:size:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeValueOfObjCType_at_size(
            &self,
            r#type: NonNull<c_char>,
            data: NonNull<c_void>,
            size: NSUInteger,
        );

        #[cfg(feature = "NSString")]
        #[unsafe(method(versionForClassName:))]
        #[unsafe(method_family = none)]
        pub unsafe fn versionForClassName(&self, class_name: &NSString) -> NSInteger;
    );
}

/// Methods declared on superclass `NSObject`.
impl NSCoder {
    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>;
    );
}

/// NSExtendedCoder.
impl NSCoder {
    extern_methods!(
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(encodeObject:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeObject(&self, object: Option<&AnyObject>);

        /// # Safety
        ///
        /// `root_object` should be of the correct type.
        #[unsafe(method(encodeRootObject:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeRootObject(&self, root_object: &AnyObject);

        /// # Safety
        ///
        /// `an_object` should be of the correct type.
        #[unsafe(method(encodeBycopyObject:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeBycopyObject(&self, an_object: Option<&AnyObject>);

        /// # Safety
        ///
        /// `an_object` should be of the correct type.
        #[unsafe(method(encodeByrefObject:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeByrefObject(&self, an_object: Option<&AnyObject>);

        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(encodeConditionalObject:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeConditionalObject(&self, object: Option<&AnyObject>);

        /// # Safety
        ///
        /// - `type` must be a valid pointer.
        /// - `array` must be a valid pointer.
        #[unsafe(method(encodeArrayOfObjCType:count:at:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeArrayOfObjCType_count_at(
            &self,
            r#type: NonNull<c_char>,
            count: NSUInteger,
            array: NonNull<c_void>,
        );

        /// # Safety
        ///
        /// `byteaddr` must be a valid pointer or null.
        #[unsafe(method(encodeBytes:length:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeBytes_length(&self, byteaddr: *const c_void, length: NSUInteger);

        #[unsafe(method(decodeObject))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeObject(&self) -> Option<Retained<AnyObject>>;

        #[cfg(feature = "NSError")]
        #[unsafe(method(decodeTopLevelObjectAndReturnError:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeTopLevelObjectAndReturnError(
            &self,
        ) -> Result<Retained<AnyObject>, Retained<NSError>>;

        /// # Safety
        ///
        /// - `item_type` must be a valid pointer.
        /// - `array` must be a valid pointer.
        #[unsafe(method(decodeArrayOfObjCType:count:at:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeArrayOfObjCType_count_at(
            &self,
            item_type: NonNull<c_char>,
            count: NSUInteger,
            array: NonNull<c_void>,
        );

        /// # Safety
        ///
        /// `lengthp` must be a valid pointer.
        #[unsafe(method(decodeBytesWithReturnedLength:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeBytesWithReturnedLength(
            &self,
            lengthp: NonNull<NSUInteger>,
        ) -> *mut c_void;

        /// # Safety
        ///
        /// `a_property_list` should be of the correct type.
        #[unsafe(method(encodePropertyList:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodePropertyList(&self, a_property_list: &AnyObject);

        #[unsafe(method(decodePropertyList))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodePropertyList(&self) -> Option<Retained<AnyObject>>;

        #[cfg(feature = "NSZone")]
        /// # Safety
        ///
        /// `zone` must be a valid pointer or null.
        #[unsafe(method(setObjectZone:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setObjectZone(&self, zone: *mut NSZone);

        #[cfg(feature = "NSZone")]
        #[unsafe(method(objectZone))]
        #[unsafe(method_family = none)]
        pub unsafe fn objectZone(&self) -> *mut NSZone;

        #[unsafe(method(systemVersion))]
        #[unsafe(method_family = none)]
        pub unsafe fn systemVersion(&self) -> c_uint;

        #[unsafe(method(allowsKeyedCoding))]
        #[unsafe(method_family = none)]
        pub unsafe fn allowsKeyedCoding(&self) -> bool;

        #[cfg(feature = "NSString")]
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(encodeObject:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeObject_forKey(&self, object: Option<&AnyObject>, key: &NSString);

        #[cfg(feature = "NSString")]
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(encodeConditionalObject:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeConditionalObject_forKey(
            &self,
            object: Option<&AnyObject>,
            key: &NSString,
        );

        #[cfg(feature = "NSString")]
        #[unsafe(method(encodeBool:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeBool_forKey(&self, value: bool, key: &NSString);

        #[cfg(feature = "NSString")]
        #[unsafe(method(encodeInt:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeInt_forKey(&self, value: c_int, key: &NSString);

        #[cfg(feature = "NSString")]
        #[unsafe(method(encodeInt32:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeInt32_forKey(&self, value: i32, key: &NSString);

        #[cfg(feature = "NSString")]
        #[unsafe(method(encodeInt64:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeInt64_forKey(&self, value: i64, key: &NSString);

        #[cfg(feature = "NSString")]
        #[unsafe(method(encodeFloat:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeFloat_forKey(&self, value: c_float, key: &NSString);

        #[cfg(feature = "NSString")]
        #[unsafe(method(encodeDouble:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeDouble_forKey(&self, value: c_double, key: &NSString);

        #[cfg(feature = "NSString")]
        /// # Safety
        ///
        /// `bytes` must be a valid pointer or null.
        #[unsafe(method(encodeBytes:length:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeBytes_length_forKey(
            &self,
            bytes: *const u8,
            length: NSUInteger,
            key: &NSString,
        );

        #[cfg(feature = "NSString")]
        #[unsafe(method(containsValueForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn containsValueForKey(&self, key: &NSString) -> bool;

        #[cfg(feature = "NSString")]
        #[unsafe(method(decodeObjectForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeObjectForKey(&self, key: &NSString) -> Option<Retained<AnyObject>>;

        #[cfg(all(feature = "NSError", feature = "NSString"))]
        #[unsafe(method(decodeTopLevelObjectForKey:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeTopLevelObjectForKey_error(
            &self,
            key: &NSString,
        ) -> Result<Retained<AnyObject>, Retained<NSError>>;

        #[cfg(feature = "NSString")]
        #[unsafe(method(decodeBoolForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeBoolForKey(&self, key: &NSString) -> bool;

        #[cfg(feature = "NSString")]
        #[unsafe(method(decodeIntForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeIntForKey(&self, key: &NSString) -> c_int;

        #[cfg(feature = "NSString")]
        #[unsafe(method(decodeInt32ForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeInt32ForKey(&self, key: &NSString) -> i32;

        #[cfg(feature = "NSString")]
        #[unsafe(method(decodeInt64ForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeInt64ForKey(&self, key: &NSString) -> i64;

        #[cfg(feature = "NSString")]
        #[unsafe(method(decodeFloatForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeFloatForKey(&self, key: &NSString) -> c_float;

        #[cfg(feature = "NSString")]
        #[unsafe(method(decodeDoubleForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeDoubleForKey(&self, key: &NSString) -> c_double;

        #[cfg(feature = "NSString")]
        /// # Safety
        ///
        /// `lengthp` must be a valid pointer or null.
        #[unsafe(method(decodeBytesForKey:returnedLength:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeBytesForKey_returnedLength(
            &self,
            key: &NSString,
            lengthp: *mut NSUInteger,
        ) -> *const u8;

        /// Decode bytes from the decoder. The length of the bytes must be greater than or equal to the `length` parameter.
        /// If the result exists, but is of insufficient length, then the decoder uses `failWithError` to fail the entire decode operation. The result of that is configurable on a per-NSCoder basis using `NSDecodingFailurePolicy`.
        #[unsafe(method(decodeBytesWithMinimumLength:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeBytesWithMinimumLength(&self, length: NSUInteger) -> *mut c_void;

        #[cfg(feature = "NSString")]
        /// Decode bytes from the decoder for a given key. The length of the bytes must be greater than or equal to the `length` parameter.
        /// If the result exists, but is of insufficient length, then the decoder uses `failWithError` to fail the entire decode operation. The result of that is configurable on a per-NSCoder basis using `NSDecodingFailurePolicy`.
        #[unsafe(method(decodeBytesForKey:minimumLength:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeBytesForKey_minimumLength(
            &self,
            key: &NSString,
            length: NSUInteger,
        ) -> *const u8;

        #[cfg(feature = "NSString")]
        #[unsafe(method(encodeInteger:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeInteger_forKey(&self, value: NSInteger, key: &NSString);

        #[cfg(feature = "NSString")]
        #[unsafe(method(decodeIntegerForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeIntegerForKey(&self, key: &NSString) -> NSInteger;

        #[unsafe(method(requiresSecureCoding))]
        #[unsafe(method_family = none)]
        pub unsafe fn requiresSecureCoding(&self) -> bool;

        #[cfg(feature = "NSString")]
        /// # Safety
        ///
        /// `a_class` probably has further requirements.
        #[unsafe(method(decodeObjectOfClass:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeObjectOfClass_forKey(
            &self,
            a_class: &AnyClass,
            key: &NSString,
        ) -> Option<Retained<AnyObject>>;

        #[cfg(all(feature = "NSError", feature = "NSString"))]
        /// # Safety
        ///
        /// `a_class` probably has further requirements.
        #[unsafe(method(decodeTopLevelObjectOfClass:forKey:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeTopLevelObjectOfClass_forKey_error(
            &self,
            a_class: &AnyClass,
            key: &NSString,
        ) -> Result<Retained<AnyObject>, Retained<NSError>>;

        #[cfg(all(feature = "NSArray", feature = "NSString"))]
        /// Decodes the
        /// `NSArray`object for the given
        /// `key,`which should be an
        /// `NSArray<cls>,`containing the given non-collection class (no nested arrays or arrays of dictionaries, etc) from the coder.
        ///
        /// Requires
        /// `NSSecureCoding`otherwise an exception is thrown and sets the
        /// `decodingFailurePolicy`to
        /// `NSDecodingFailurePolicySetErrorAndReturn.`
        /// Returns
        /// `nil`if the object for
        /// `key`is not of the expected types, or cannot be decoded, and sets the
        /// `error`on the decoder.
        ///
        /// # Safety
        ///
        /// `cls` probably has further requirements.
        #[unsafe(method(decodeArrayOfObjectsOfClass:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeArrayOfObjectsOfClass_forKey(
            &self,
            cls: &AnyClass,
            key: &NSString,
        ) -> Option<Retained<NSArray>>;

        #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
        /// Decodes the
        /// `NSDictionary`object for the given
        /// `key,`which should be an
        /// `NSDictionary<keyCls,objectCls>`, with keys of type given in
        /// `keyCls`and objects of the given non-collection class
        /// `objectCls`(no nested dictionaries or other dictionaries contained in the dictionary, etc) from the coder.
        ///
        /// Requires
        /// `NSSecureCoding`otherwise an exception is thrown and sets the
        /// `decodingFailurePolicy`to
        /// `NSDecodingFailurePolicySetErrorAndReturn.`
        /// Returns
        /// `nil`if the object for
        /// `key`is not of the expected types, or cannot be decoded, and sets the
        /// `error`on the decoder.
        ///
        /// # Safety
        ///
        /// - `key_cls` probably has further requirements.
        /// - `object_cls` probably has further requirements.
        #[unsafe(method(decodeDictionaryWithKeysOfClass:objectsOfClass:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeDictionaryWithKeysOfClass_objectsOfClass_forKey(
            &self,
            key_cls: &AnyClass,
            object_cls: &AnyClass,
            key: &NSString,
        ) -> Option<Retained<NSDictionary>>;

        #[cfg(all(feature = "NSSet", feature = "NSString"))]
        /// # Safety
        ///
        /// `classes` generic probably has further requirements.
        #[unsafe(method(decodeObjectOfClasses:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeObjectOfClasses_forKey(
            &self,
            classes: Option<&NSSet<AnyClass>>,
            key: &NSString,
        ) -> Option<Retained<AnyObject>>;

        #[cfg(all(feature = "NSError", feature = "NSSet", feature = "NSString"))]
        /// # Safety
        ///
        /// `classes` generic probably has further requirements.
        #[unsafe(method(decodeTopLevelObjectOfClasses:forKey:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeTopLevelObjectOfClasses_forKey_error(
            &self,
            classes: Option<&NSSet<AnyClass>>,
            key: &NSString,
        ) -> Result<Retained<AnyObject>, Retained<NSError>>;

        #[cfg(all(feature = "NSArray", feature = "NSSet", feature = "NSString"))]
        /// Decodes the
        /// `NSArray`object for the given
        /// `key,`which should be an
        /// `NSArray,`containing the given non-collection classes (no nested arrays or arrays of dictionaries, etc) from the coder.
        ///
        /// Requires
        /// `NSSecureCoding`otherwise an exception is thrown and sets the
        /// `decodingFailurePolicy`to
        /// `NSDecodingFailurePolicySetErrorAndReturn.`
        /// Returns
        /// `nil`if the object for
        /// `key`is not of the expected types, or cannot be decoded, and sets the
        /// `error`on the decoder.
        ///
        /// # Safety
        ///
        /// `classes` generic probably has further requirements.
        #[unsafe(method(decodeArrayOfObjectsOfClasses:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeArrayOfObjectsOfClasses_forKey(
            &self,
            classes: &NSSet<AnyClass>,
            key: &NSString,
        ) -> Option<Retained<NSArray>>;

        #[cfg(all(feature = "NSDictionary", feature = "NSSet", feature = "NSString"))]
        /// Decodes the
        /// `NSDictionary`object for the given
        /// `key,`which should be an
        /// `NSDictionary,`with keys of the types given in
        /// `keyClasses`and objects of the given non-collection classes in
        /// `objectClasses`(no nested dictionaries or other dictionaries contained in the dictionary, etc) from the given coder.
        ///
        /// Requires
        /// `NSSecureCoding`otherwise an exception is thrown and sets the
        /// `decodingFailurePolicy`to
        /// `NSDecodingFailurePolicySetErrorAndReturn.`
        /// Returns
        /// `nil`if the object for
        /// `key`is not of the expected types, or cannot be decoded, and sets the
        /// `error`on the decoder.
        ///
        /// # Safety
        ///
        /// - `key_classes` generic probably has further requirements.
        /// - `object_classes` generic probably has further requirements.
        #[unsafe(method(decodeDictionaryWithKeysOfClasses:objectsOfClasses:forKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeDictionaryWithKeysOfClasses_objectsOfClasses_forKey(
            &self,
            key_classes: &NSSet<AnyClass>,
            object_classes: &NSSet<AnyClass>,
            key: &NSString,
        ) -> Option<Retained<NSDictionary>>;

        #[cfg(feature = "NSString")]
        #[unsafe(method(decodePropertyListForKey:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodePropertyListForKey(
            &self,
            key: &NSString,
        ) -> Option<Retained<AnyObject>>;

        #[cfg(feature = "NSSet")]
        #[unsafe(method(allowedClasses))]
        #[unsafe(method_family = none)]
        pub unsafe fn allowedClasses(&self) -> Option<Retained<NSSet<AnyClass>>>;

        #[cfg(feature = "NSError")]
        /// Signals to this coder that the decode has failed.
        /// Parameter non-nil error that describes the reason why the decode failed
        ///
        /// Sets an error on this NSCoder once per TopLevel decode; calling it repeatedly will have no effect until the call stack unwinds to one of the TopLevel decode entry-points.
        ///
        /// This method is only meaningful to call for decodes.
        ///
        /// Typically, you would want to call this method in your -initWithCoder: implementation when you detect situations like:
        /// - lack of secure coding
        /// - corruption of your data
        /// - domain validation failures
        ///
        /// After calling -failWithError: within your -initWithCoder: implementation, you should clean up and return nil as early as possible.
        ///
        /// Once an error has been signaled to a decoder, it remains set until it has handed off to the first TopLevel decode invocation above it.  For example, consider the following call graph:
        /// A    -decodeTopLevelObjectForKey:error:
        /// B        -initWithCoder:
        /// C            -decodeObjectForKey:
        /// D                -initWithCoder:
        /// E                    -decodeObjectForKey:
        /// F                        -failWithError:
        ///
        /// In this case the error provided in stack-frame F will be returned via the outError in stack-frame A. Furthermore the result object from decodeTopLevelObjectForKey:error: will be nil, regardless of the result of stack-frame B.
        ///
        /// NSCoder implementations support two mechanisms for the stack-unwinding from F to A:
        /// - forced (NSException based)
        /// - particpatory (error based)
        ///
        /// The kind of unwinding you get is determined by the decodingFailurePolicy property of this NSCoder (which defaults to NSDecodingFailurePolicyRaiseException to match historical behavior).
        #[unsafe(method(failWithError:))]
        #[unsafe(method_family = none)]
        pub unsafe fn failWithError(&self, error: &NSError);

        /// Defines the behavior this NSCoder should take on decode failure (i.e. corrupt archive, invalid data, etc.).
        ///
        /// The default result of this property is NSDecodingFailurePolicyRaiseException, subclasses can change this to an alternative policy.
        #[unsafe(method(decodingFailurePolicy))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodingFailurePolicy(&self) -> NSDecodingFailurePolicy;

        #[cfg(feature = "NSError")]
        /// The current error (if there is one) for the current TopLevel decode.
        ///
        /// The meaning of this property changes based on the result of the decodingFailurePolicy property:
        /// For NSDecodingFailurePolicyRaiseException, this property will always be nil.
        /// For NSDecodingFailurePolicySetErrorAndReturn, this property can be non-nil, and if so, indicates that there was a failure while decoding the archive (specifically its the very first error encountered).
        ///
        /// While .error is non-nil, all attempts to decode data from this coder will return a nil/zero-equivalent value.
        ///
        /// This error is consumed by a TopLevel decode API (which resets this coder back to a being able to potentially decode data).
        #[unsafe(method(error))]
        #[unsafe(method_family = none)]
        pub unsafe fn error(&self) -> Option<Retained<NSError>>;
    );
}

/// # Safety
///
/// `decoder` possibly has further requirements.
#[deprecated = "Not supported"]
#[inline]
pub unsafe extern "C-unwind" fn NXReadNSObjectFromCoder(
    decoder: &NSCoder,
) -> Option<Retained<NSObject>> {
    extern "C-unwind" {
        fn NXReadNSObjectFromCoder(decoder: &NSCoder) -> *mut NSObject;
    }
    let ret = unsafe { NXReadNSObjectFromCoder(decoder) };
    unsafe { Retained::retain_autoreleased(ret) }
}

/// NSTypedstreamCompatibility.
impl NSCoder {
    extern_methods!(
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[deprecated = "Not supported"]
        #[unsafe(method(encodeNXObject:))]
        #[unsafe(method_family = none)]
        pub unsafe fn encodeNXObject(&self, object: &AnyObject);

        #[deprecated = "Not supported"]
        #[unsafe(method(decodeNXObject))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeNXObject(&self) -> Option<Retained<AnyObject>>;
    );
}

/// NSDeprecated.
impl NSCoder {
    extern_methods!(
        /// # Safety
        ///
        /// - `type` must be a valid pointer.
        /// - `data` must be a valid pointer.
        #[deprecated]
        #[unsafe(method(decodeValueOfObjCType:at:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decodeValueOfObjCType_at(
            &self,
            r#type: NonNull<c_char>,
            data: NonNull<c_void>,
        );
    );
}