objc2_foundation/generated/
NSCoder.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::*;
6
7use crate::*;
8
9/// Describes the action an NSCoder should take when it encounters decode failures (e.g. corrupt data) for non-TopLevel decodes.
10///
11/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdecodingfailurepolicy?language=objc)
12// NS_ENUM
13#[repr(transparent)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct NSDecodingFailurePolicy(pub NSInteger);
16impl NSDecodingFailurePolicy {
17    #[doc(alias = "NSDecodingFailurePolicyRaiseException")]
18    pub const RaiseException: Self = Self(0);
19    #[doc(alias = "NSDecodingFailurePolicySetErrorAndReturn")]
20    pub const SetErrorAndReturn: Self = Self(1);
21}
22
23unsafe impl Encode for NSDecodingFailurePolicy {
24    const ENCODING: Encoding = NSInteger::ENCODING;
25}
26
27unsafe impl RefEncode for NSDecodingFailurePolicy {
28    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
29}
30
31extern_class!(
32    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nscoder?language=objc)
33    #[unsafe(super(NSObject))]
34    #[derive(Debug, PartialEq, Eq, Hash)]
35    pub struct NSCoder;
36);
37
38extern_conformance!(
39    unsafe impl NSObjectProtocol for NSCoder {}
40);
41
42impl NSCoder {
43    extern_methods!(
44        /// # Safety
45        ///
46        /// - `type` must be a valid pointer.
47        /// - `addr` must be a valid pointer.
48        #[unsafe(method(encodeValueOfObjCType:at:))]
49        #[unsafe(method_family = none)]
50        pub unsafe fn encodeValueOfObjCType_at(
51            &self,
52            r#type: NonNull<c_char>,
53            addr: NonNull<c_void>,
54        );
55
56        #[cfg(feature = "NSData")]
57        #[unsafe(method(encodeDataObject:))]
58        #[unsafe(method_family = none)]
59        pub unsafe fn encodeDataObject(&self, data: &NSData);
60
61        #[cfg(feature = "NSData")]
62        #[unsafe(method(decodeDataObject))]
63        #[unsafe(method_family = none)]
64        pub unsafe fn decodeDataObject(&self) -> Option<Retained<NSData>>;
65
66        /// # Safety
67        ///
68        /// - `type` must be a valid pointer.
69        /// - `data` must be a valid pointer.
70        #[unsafe(method(decodeValueOfObjCType:at:size:))]
71        #[unsafe(method_family = none)]
72        pub unsafe fn decodeValueOfObjCType_at_size(
73            &self,
74            r#type: NonNull<c_char>,
75            data: NonNull<c_void>,
76            size: NSUInteger,
77        );
78
79        #[cfg(feature = "NSString")]
80        #[unsafe(method(versionForClassName:))]
81        #[unsafe(method_family = none)]
82        pub unsafe fn versionForClassName(&self, class_name: &NSString) -> NSInteger;
83    );
84}
85
86/// Methods declared on superclass `NSObject`.
87impl NSCoder {
88    extern_methods!(
89        #[unsafe(method(init))]
90        #[unsafe(method_family = init)]
91        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
92
93        #[unsafe(method(new))]
94        #[unsafe(method_family = new)]
95        pub unsafe fn new() -> Retained<Self>;
96    );
97}
98
99/// NSExtendedCoder.
100impl NSCoder {
101    extern_methods!(
102        /// # Safety
103        ///
104        /// `object` should be of the correct type.
105        #[unsafe(method(encodeObject:))]
106        #[unsafe(method_family = none)]
107        pub unsafe fn encodeObject(&self, object: Option<&AnyObject>);
108
109        /// # Safety
110        ///
111        /// `root_object` should be of the correct type.
112        #[unsafe(method(encodeRootObject:))]
113        #[unsafe(method_family = none)]
114        pub unsafe fn encodeRootObject(&self, root_object: &AnyObject);
115
116        /// # Safety
117        ///
118        /// `an_object` should be of the correct type.
119        #[unsafe(method(encodeBycopyObject:))]
120        #[unsafe(method_family = none)]
121        pub unsafe fn encodeBycopyObject(&self, an_object: Option<&AnyObject>);
122
123        /// # Safety
124        ///
125        /// `an_object` should be of the correct type.
126        #[unsafe(method(encodeByrefObject:))]
127        #[unsafe(method_family = none)]
128        pub unsafe fn encodeByrefObject(&self, an_object: Option<&AnyObject>);
129
130        /// # Safety
131        ///
132        /// `object` should be of the correct type.
133        #[unsafe(method(encodeConditionalObject:))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn encodeConditionalObject(&self, object: Option<&AnyObject>);
136
137        /// # Safety
138        ///
139        /// - `type` must be a valid pointer.
140        /// - `array` must be a valid pointer.
141        #[unsafe(method(encodeArrayOfObjCType:count:at:))]
142        #[unsafe(method_family = none)]
143        pub unsafe fn encodeArrayOfObjCType_count_at(
144            &self,
145            r#type: NonNull<c_char>,
146            count: NSUInteger,
147            array: NonNull<c_void>,
148        );
149
150        /// # Safety
151        ///
152        /// `byteaddr` must be a valid pointer or null.
153        #[unsafe(method(encodeBytes:length:))]
154        #[unsafe(method_family = none)]
155        pub unsafe fn encodeBytes_length(&self, byteaddr: *const c_void, length: NSUInteger);
156
157        #[unsafe(method(decodeObject))]
158        #[unsafe(method_family = none)]
159        pub unsafe fn decodeObject(&self) -> Option<Retained<AnyObject>>;
160
161        #[cfg(feature = "NSError")]
162        #[unsafe(method(decodeTopLevelObjectAndReturnError:_))]
163        #[unsafe(method_family = none)]
164        pub unsafe fn decodeTopLevelObjectAndReturnError(
165            &self,
166        ) -> Result<Retained<AnyObject>, Retained<NSError>>;
167
168        /// # Safety
169        ///
170        /// - `item_type` must be a valid pointer.
171        /// - `array` must be a valid pointer.
172        #[unsafe(method(decodeArrayOfObjCType:count:at:))]
173        #[unsafe(method_family = none)]
174        pub unsafe fn decodeArrayOfObjCType_count_at(
175            &self,
176            item_type: NonNull<c_char>,
177            count: NSUInteger,
178            array: NonNull<c_void>,
179        );
180
181        /// # Safety
182        ///
183        /// `lengthp` must be a valid pointer.
184        #[unsafe(method(decodeBytesWithReturnedLength:))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn decodeBytesWithReturnedLength(
187            &self,
188            lengthp: NonNull<NSUInteger>,
189        ) -> *mut c_void;
190
191        /// # Safety
192        ///
193        /// `a_property_list` should be of the correct type.
194        #[unsafe(method(encodePropertyList:))]
195        #[unsafe(method_family = none)]
196        pub unsafe fn encodePropertyList(&self, a_property_list: &AnyObject);
197
198        #[unsafe(method(decodePropertyList))]
199        #[unsafe(method_family = none)]
200        pub unsafe fn decodePropertyList(&self) -> Option<Retained<AnyObject>>;
201
202        #[cfg(feature = "NSZone")]
203        /// # Safety
204        ///
205        /// `zone` must be a valid pointer or null.
206        #[unsafe(method(setObjectZone:))]
207        #[unsafe(method_family = none)]
208        pub unsafe fn setObjectZone(&self, zone: *mut NSZone);
209
210        #[cfg(feature = "NSZone")]
211        #[unsafe(method(objectZone))]
212        #[unsafe(method_family = none)]
213        pub unsafe fn objectZone(&self) -> *mut NSZone;
214
215        #[unsafe(method(systemVersion))]
216        #[unsafe(method_family = none)]
217        pub unsafe fn systemVersion(&self) -> c_uint;
218
219        #[unsafe(method(allowsKeyedCoding))]
220        #[unsafe(method_family = none)]
221        pub unsafe fn allowsKeyedCoding(&self) -> bool;
222
223        #[cfg(feature = "NSString")]
224        /// # Safety
225        ///
226        /// `object` should be of the correct type.
227        #[unsafe(method(encodeObject:forKey:))]
228        #[unsafe(method_family = none)]
229        pub unsafe fn encodeObject_forKey(&self, object: Option<&AnyObject>, key: &NSString);
230
231        #[cfg(feature = "NSString")]
232        /// # Safety
233        ///
234        /// `object` should be of the correct type.
235        #[unsafe(method(encodeConditionalObject:forKey:))]
236        #[unsafe(method_family = none)]
237        pub unsafe fn encodeConditionalObject_forKey(
238            &self,
239            object: Option<&AnyObject>,
240            key: &NSString,
241        );
242
243        #[cfg(feature = "NSString")]
244        #[unsafe(method(encodeBool:forKey:))]
245        #[unsafe(method_family = none)]
246        pub unsafe fn encodeBool_forKey(&self, value: bool, key: &NSString);
247
248        #[cfg(feature = "NSString")]
249        #[unsafe(method(encodeInt:forKey:))]
250        #[unsafe(method_family = none)]
251        pub unsafe fn encodeInt_forKey(&self, value: c_int, key: &NSString);
252
253        #[cfg(feature = "NSString")]
254        #[unsafe(method(encodeInt32:forKey:))]
255        #[unsafe(method_family = none)]
256        pub unsafe fn encodeInt32_forKey(&self, value: i32, key: &NSString);
257
258        #[cfg(feature = "NSString")]
259        #[unsafe(method(encodeInt64:forKey:))]
260        #[unsafe(method_family = none)]
261        pub unsafe fn encodeInt64_forKey(&self, value: i64, key: &NSString);
262
263        #[cfg(feature = "NSString")]
264        #[unsafe(method(encodeFloat:forKey:))]
265        #[unsafe(method_family = none)]
266        pub unsafe fn encodeFloat_forKey(&self, value: c_float, key: &NSString);
267
268        #[cfg(feature = "NSString")]
269        #[unsafe(method(encodeDouble:forKey:))]
270        #[unsafe(method_family = none)]
271        pub unsafe fn encodeDouble_forKey(&self, value: c_double, key: &NSString);
272
273        #[cfg(feature = "NSString")]
274        /// # Safety
275        ///
276        /// `bytes` must be a valid pointer or null.
277        #[unsafe(method(encodeBytes:length:forKey:))]
278        #[unsafe(method_family = none)]
279        pub unsafe fn encodeBytes_length_forKey(
280            &self,
281            bytes: *const u8,
282            length: NSUInteger,
283            key: &NSString,
284        );
285
286        #[cfg(feature = "NSString")]
287        #[unsafe(method(containsValueForKey:))]
288        #[unsafe(method_family = none)]
289        pub unsafe fn containsValueForKey(&self, key: &NSString) -> bool;
290
291        #[cfg(feature = "NSString")]
292        #[unsafe(method(decodeObjectForKey:))]
293        #[unsafe(method_family = none)]
294        pub unsafe fn decodeObjectForKey(&self, key: &NSString) -> Option<Retained<AnyObject>>;
295
296        #[cfg(all(feature = "NSError", feature = "NSString"))]
297        #[unsafe(method(decodeTopLevelObjectForKey:error:_))]
298        #[unsafe(method_family = none)]
299        pub unsafe fn decodeTopLevelObjectForKey_error(
300            &self,
301            key: &NSString,
302        ) -> Result<Retained<AnyObject>, Retained<NSError>>;
303
304        #[cfg(feature = "NSString")]
305        #[unsafe(method(decodeBoolForKey:))]
306        #[unsafe(method_family = none)]
307        pub unsafe fn decodeBoolForKey(&self, key: &NSString) -> bool;
308
309        #[cfg(feature = "NSString")]
310        #[unsafe(method(decodeIntForKey:))]
311        #[unsafe(method_family = none)]
312        pub unsafe fn decodeIntForKey(&self, key: &NSString) -> c_int;
313
314        #[cfg(feature = "NSString")]
315        #[unsafe(method(decodeInt32ForKey:))]
316        #[unsafe(method_family = none)]
317        pub unsafe fn decodeInt32ForKey(&self, key: &NSString) -> i32;
318
319        #[cfg(feature = "NSString")]
320        #[unsafe(method(decodeInt64ForKey:))]
321        #[unsafe(method_family = none)]
322        pub unsafe fn decodeInt64ForKey(&self, key: &NSString) -> i64;
323
324        #[cfg(feature = "NSString")]
325        #[unsafe(method(decodeFloatForKey:))]
326        #[unsafe(method_family = none)]
327        pub unsafe fn decodeFloatForKey(&self, key: &NSString) -> c_float;
328
329        #[cfg(feature = "NSString")]
330        #[unsafe(method(decodeDoubleForKey:))]
331        #[unsafe(method_family = none)]
332        pub unsafe fn decodeDoubleForKey(&self, key: &NSString) -> c_double;
333
334        #[cfg(feature = "NSString")]
335        /// # Safety
336        ///
337        /// `lengthp` must be a valid pointer or null.
338        #[unsafe(method(decodeBytesForKey:returnedLength:))]
339        #[unsafe(method_family = none)]
340        pub unsafe fn decodeBytesForKey_returnedLength(
341            &self,
342            key: &NSString,
343            lengthp: *mut NSUInteger,
344        ) -> *const u8;
345
346        /// Decode bytes from the decoder. The length of the bytes must be greater than or equal to the `length` parameter.
347        /// 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`.
348        #[unsafe(method(decodeBytesWithMinimumLength:))]
349        #[unsafe(method_family = none)]
350        pub unsafe fn decodeBytesWithMinimumLength(&self, length: NSUInteger) -> *mut c_void;
351
352        #[cfg(feature = "NSString")]
353        /// Decode bytes from the decoder for a given key. The length of the bytes must be greater than or equal to the `length` parameter.
354        /// 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`.
355        #[unsafe(method(decodeBytesForKey:minimumLength:))]
356        #[unsafe(method_family = none)]
357        pub unsafe fn decodeBytesForKey_minimumLength(
358            &self,
359            key: &NSString,
360            length: NSUInteger,
361        ) -> *const u8;
362
363        #[cfg(feature = "NSString")]
364        #[unsafe(method(encodeInteger:forKey:))]
365        #[unsafe(method_family = none)]
366        pub unsafe fn encodeInteger_forKey(&self, value: NSInteger, key: &NSString);
367
368        #[cfg(feature = "NSString")]
369        #[unsafe(method(decodeIntegerForKey:))]
370        #[unsafe(method_family = none)]
371        pub unsafe fn decodeIntegerForKey(&self, key: &NSString) -> NSInteger;
372
373        #[unsafe(method(requiresSecureCoding))]
374        #[unsafe(method_family = none)]
375        pub unsafe fn requiresSecureCoding(&self) -> bool;
376
377        #[cfg(feature = "NSString")]
378        /// # Safety
379        ///
380        /// `a_class` probably has further requirements.
381        #[unsafe(method(decodeObjectOfClass:forKey:))]
382        #[unsafe(method_family = none)]
383        pub unsafe fn decodeObjectOfClass_forKey(
384            &self,
385            a_class: &AnyClass,
386            key: &NSString,
387        ) -> Option<Retained<AnyObject>>;
388
389        #[cfg(all(feature = "NSError", feature = "NSString"))]
390        /// # Safety
391        ///
392        /// `a_class` probably has further requirements.
393        #[unsafe(method(decodeTopLevelObjectOfClass:forKey:error:_))]
394        #[unsafe(method_family = none)]
395        pub unsafe fn decodeTopLevelObjectOfClass_forKey_error(
396            &self,
397            a_class: &AnyClass,
398            key: &NSString,
399        ) -> Result<Retained<AnyObject>, Retained<NSError>>;
400
401        #[cfg(all(feature = "NSArray", feature = "NSString"))]
402        /// Decodes the
403        /// `NSArray`object for the given
404        /// `key,`which should be an
405        /// `NSArray<cls>,`containing the given non-collection class (no nested arrays or arrays of dictionaries, etc) from the coder.
406        ///
407        /// Requires
408        /// `NSSecureCoding`otherwise an exception is thrown and sets the
409        /// `decodingFailurePolicy`to
410        /// `NSDecodingFailurePolicySetErrorAndReturn.`
411        /// Returns
412        /// `nil`if the object for
413        /// `key`is not of the expected types, or cannot be decoded, and sets the
414        /// `error`on the decoder.
415        ///
416        /// # Safety
417        ///
418        /// `cls` probably has further requirements.
419        #[unsafe(method(decodeArrayOfObjectsOfClass:forKey:))]
420        #[unsafe(method_family = none)]
421        pub unsafe fn decodeArrayOfObjectsOfClass_forKey(
422            &self,
423            cls: &AnyClass,
424            key: &NSString,
425        ) -> Option<Retained<NSArray>>;
426
427        #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
428        /// Decodes the
429        /// `NSDictionary`object for the given
430        /// `key,`which should be an
431        /// `NSDictionary<keyCls,objectCls>`, with keys of type given in
432        /// `keyCls`and objects of the given non-collection class
433        /// `objectCls`(no nested dictionaries or other dictionaries contained in the dictionary, etc) from the coder.
434        ///
435        /// Requires
436        /// `NSSecureCoding`otherwise an exception is thrown and sets the
437        /// `decodingFailurePolicy`to
438        /// `NSDecodingFailurePolicySetErrorAndReturn.`
439        /// Returns
440        /// `nil`if the object for
441        /// `key`is not of the expected types, or cannot be decoded, and sets the
442        /// `error`on the decoder.
443        ///
444        /// # Safety
445        ///
446        /// - `key_cls` probably has further requirements.
447        /// - `object_cls` probably has further requirements.
448        #[unsafe(method(decodeDictionaryWithKeysOfClass:objectsOfClass:forKey:))]
449        #[unsafe(method_family = none)]
450        pub unsafe fn decodeDictionaryWithKeysOfClass_objectsOfClass_forKey(
451            &self,
452            key_cls: &AnyClass,
453            object_cls: &AnyClass,
454            key: &NSString,
455        ) -> Option<Retained<NSDictionary>>;
456
457        #[cfg(all(feature = "NSSet", feature = "NSString"))]
458        /// # Safety
459        ///
460        /// `classes` generic probably has further requirements.
461        #[unsafe(method(decodeObjectOfClasses:forKey:))]
462        #[unsafe(method_family = none)]
463        pub unsafe fn decodeObjectOfClasses_forKey(
464            &self,
465            classes: Option<&NSSet<AnyClass>>,
466            key: &NSString,
467        ) -> Option<Retained<AnyObject>>;
468
469        #[cfg(all(feature = "NSError", feature = "NSSet", feature = "NSString"))]
470        /// # Safety
471        ///
472        /// `classes` generic probably has further requirements.
473        #[unsafe(method(decodeTopLevelObjectOfClasses:forKey:error:_))]
474        #[unsafe(method_family = none)]
475        pub unsafe fn decodeTopLevelObjectOfClasses_forKey_error(
476            &self,
477            classes: Option<&NSSet<AnyClass>>,
478            key: &NSString,
479        ) -> Result<Retained<AnyObject>, Retained<NSError>>;
480
481        #[cfg(all(feature = "NSArray", feature = "NSSet", feature = "NSString"))]
482        /// Decodes the
483        /// `NSArray`object for the given
484        /// `key,`which should be an
485        /// `NSArray,`containing the given non-collection classes (no nested arrays or arrays of dictionaries, etc) from the coder.
486        ///
487        /// Requires
488        /// `NSSecureCoding`otherwise an exception is thrown and sets the
489        /// `decodingFailurePolicy`to
490        /// `NSDecodingFailurePolicySetErrorAndReturn.`
491        /// Returns
492        /// `nil`if the object for
493        /// `key`is not of the expected types, or cannot be decoded, and sets the
494        /// `error`on the decoder.
495        ///
496        /// # Safety
497        ///
498        /// `classes` generic probably has further requirements.
499        #[unsafe(method(decodeArrayOfObjectsOfClasses:forKey:))]
500        #[unsafe(method_family = none)]
501        pub unsafe fn decodeArrayOfObjectsOfClasses_forKey(
502            &self,
503            classes: &NSSet<AnyClass>,
504            key: &NSString,
505        ) -> Option<Retained<NSArray>>;
506
507        #[cfg(all(feature = "NSDictionary", feature = "NSSet", feature = "NSString"))]
508        /// Decodes the
509        /// `NSDictionary`object for the given
510        /// `key,`which should be an
511        /// `NSDictionary,`with keys of the types given in
512        /// `keyClasses`and objects of the given non-collection classes in
513        /// `objectClasses`(no nested dictionaries or other dictionaries contained in the dictionary, etc) from the given coder.
514        ///
515        /// Requires
516        /// `NSSecureCoding`otherwise an exception is thrown and sets the
517        /// `decodingFailurePolicy`to
518        /// `NSDecodingFailurePolicySetErrorAndReturn.`
519        /// Returns
520        /// `nil`if the object for
521        /// `key`is not of the expected types, or cannot be decoded, and sets the
522        /// `error`on the decoder.
523        ///
524        /// # Safety
525        ///
526        /// - `key_classes` generic probably has further requirements.
527        /// - `object_classes` generic probably has further requirements.
528        #[unsafe(method(decodeDictionaryWithKeysOfClasses:objectsOfClasses:forKey:))]
529        #[unsafe(method_family = none)]
530        pub unsafe fn decodeDictionaryWithKeysOfClasses_objectsOfClasses_forKey(
531            &self,
532            key_classes: &NSSet<AnyClass>,
533            object_classes: &NSSet<AnyClass>,
534            key: &NSString,
535        ) -> Option<Retained<NSDictionary>>;
536
537        #[cfg(feature = "NSString")]
538        #[unsafe(method(decodePropertyListForKey:))]
539        #[unsafe(method_family = none)]
540        pub unsafe fn decodePropertyListForKey(
541            &self,
542            key: &NSString,
543        ) -> Option<Retained<AnyObject>>;
544
545        #[cfg(feature = "NSSet")]
546        #[unsafe(method(allowedClasses))]
547        #[unsafe(method_family = none)]
548        pub unsafe fn allowedClasses(&self) -> Option<Retained<NSSet<AnyClass>>>;
549
550        #[cfg(feature = "NSError")]
551        /// Signals to this coder that the decode has failed.
552        /// Parameter non-nil error that describes the reason why the decode failed
553        ///
554        /// 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.
555        ///
556        /// This method is only meaningful to call for decodes.
557        ///
558        /// Typically, you would want to call this method in your -initWithCoder: implementation when you detect situations like:
559        /// - lack of secure coding
560        /// - corruption of your data
561        /// - domain validation failures
562        ///
563        /// After calling -failWithError: within your -initWithCoder: implementation, you should clean up and return nil as early as possible.
564        ///
565        /// 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:
566        /// A    -decodeTopLevelObjectForKey:error:
567        /// B        -initWithCoder:
568        /// C            -decodeObjectForKey:
569        /// D                -initWithCoder:
570        /// E                    -decodeObjectForKey:
571        /// F                        -failWithError:
572        ///
573        /// 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.
574        ///
575        /// NSCoder implementations support two mechanisms for the stack-unwinding from F to A:
576        /// - forced (NSException based)
577        /// - particpatory (error based)
578        ///
579        /// The kind of unwinding you get is determined by the decodingFailurePolicy property of this NSCoder (which defaults to NSDecodingFailurePolicyRaiseException to match historical behavior).
580        #[unsafe(method(failWithError:))]
581        #[unsafe(method_family = none)]
582        pub unsafe fn failWithError(&self, error: &NSError);
583
584        /// Defines the behavior this NSCoder should take on decode failure (i.e. corrupt archive, invalid data, etc.).
585        ///
586        /// The default result of this property is NSDecodingFailurePolicyRaiseException, subclasses can change this to an alternative policy.
587        #[unsafe(method(decodingFailurePolicy))]
588        #[unsafe(method_family = none)]
589        pub unsafe fn decodingFailurePolicy(&self) -> NSDecodingFailurePolicy;
590
591        #[cfg(feature = "NSError")]
592        /// The current error (if there is one) for the current TopLevel decode.
593        ///
594        /// The meaning of this property changes based on the result of the decodingFailurePolicy property:
595        /// For NSDecodingFailurePolicyRaiseException, this property will always be nil.
596        /// 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).
597        ///
598        /// While .error is non-nil, all attempts to decode data from this coder will return a nil/zero-equivalent value.
599        ///
600        /// This error is consumed by a TopLevel decode API (which resets this coder back to a being able to potentially decode data).
601        #[unsafe(method(error))]
602        #[unsafe(method_family = none)]
603        pub unsafe fn error(&self) -> Option<Retained<NSError>>;
604    );
605}
606
607/// # Safety
608///
609/// `decoder` possibly has further requirements.
610#[deprecated = "Not supported"]
611#[inline]
612pub unsafe extern "C-unwind" fn NXReadNSObjectFromCoder(
613    decoder: &NSCoder,
614) -> Option<Retained<NSObject>> {
615    extern "C-unwind" {
616        fn NXReadNSObjectFromCoder(decoder: &NSCoder) -> *mut NSObject;
617    }
618    let ret = unsafe { NXReadNSObjectFromCoder(decoder) };
619    unsafe { Retained::retain_autoreleased(ret) }
620}
621
622/// NSTypedstreamCompatibility.
623impl NSCoder {
624    extern_methods!(
625        /// # Safety
626        ///
627        /// `object` should be of the correct type.
628        #[deprecated = "Not supported"]
629        #[unsafe(method(encodeNXObject:))]
630        #[unsafe(method_family = none)]
631        pub unsafe fn encodeNXObject(&self, object: &AnyObject);
632
633        #[deprecated = "Not supported"]
634        #[unsafe(method(decodeNXObject))]
635        #[unsafe(method_family = none)]
636        pub unsafe fn decodeNXObject(&self) -> Option<Retained<AnyObject>>;
637    );
638}
639
640/// NSDeprecated.
641impl NSCoder {
642    extern_methods!(
643        /// # Safety
644        ///
645        /// - `type` must be a valid pointer.
646        /// - `data` must be a valid pointer.
647        #[deprecated]
648        #[unsafe(method(decodeValueOfObjCType:at:))]
649        #[unsafe(method_family = none)]
650        pub unsafe fn decodeValueOfObjCType_at(
651            &self,
652            r#type: NonNull<c_char>,
653            data: NonNull<c_void>,
654        );
655    );
656}