objc2_foundation/generated/
NSDictionary.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#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8
9use crate::*;
10
11extern_class!(
12    /// **************    Immutable Dictionary    ***************
13    ///
14    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdictionary?language=objc)
15    #[unsafe(super(NSObject))]
16    #[derive(PartialEq, Eq, Hash)]
17    pub struct NSDictionary<KeyType: ?Sized = AnyObject, ObjectType: ?Sized = AnyObject>;
18);
19
20#[cfg(feature = "objc2-core-foundation")]
21impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message>
22    AsRef<NSDictionary<KeyType, ObjectType>> for CFDictionary<KeyType, ObjectType>
23{
24    #[inline]
25    fn as_ref(&self) -> &NSDictionary<KeyType, ObjectType> {
26        unsafe { &*((self as *const Self).cast()) }
27    }
28}
29
30#[cfg(feature = "objc2-core-foundation")]
31impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message>
32    AsRef<CFDictionary<KeyType, ObjectType>> for NSDictionary<KeyType, ObjectType>
33{
34    #[inline]
35    fn as_ref(&self) -> &CFDictionary<KeyType, ObjectType> {
36        unsafe { &*((self as *const Self).cast()) }
37    }
38}
39
40impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message> NSDictionary<KeyType, ObjectType> {
41    /// Unchecked conversion of the generic parameters.
42    ///
43    /// # Safety
44    ///
45    /// The generics must be valid to reinterpret as the given types.
46    #[inline]
47    pub unsafe fn cast_unchecked<NewKeyType: ?Sized + Message, NewObjectType: ?Sized + Message>(
48        &self,
49    ) -> &NSDictionary<NewKeyType, NewObjectType> {
50        unsafe { &*((self as *const Self).cast()) }
51    }
52}
53
54#[cfg(feature = "NSObject")]
55extern_conformance!(
56    unsafe impl<KeyType: ?Sized + NSCoding, ObjectType: ?Sized + NSCoding> NSCoding
57        for NSDictionary<KeyType, ObjectType>
58    {
59    }
60);
61
62#[cfg(feature = "NSObject")]
63extern_conformance!(
64    unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSCopying for NSDictionary<KeyType, ObjectType> {}
65);
66
67#[cfg(feature = "NSObject")]
68unsafe impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message> CopyingHelper
69    for NSDictionary<KeyType, ObjectType>
70{
71    type Result = Self;
72}
73
74#[cfg(feature = "NSEnumerator")]
75extern_conformance!(
76    unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSFastEnumeration
77        for NSDictionary<KeyType, ObjectType>
78    {
79    }
80);
81
82#[cfg(feature = "NSObject")]
83extern_conformance!(
84    unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSMutableCopying
85        for NSDictionary<KeyType, ObjectType>
86    {
87    }
88);
89
90#[cfg(feature = "NSObject")]
91unsafe impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message> MutableCopyingHelper
92    for NSDictionary<KeyType, ObjectType>
93{
94    type Result = NSMutableDictionary<KeyType, ObjectType>;
95}
96
97extern_conformance!(
98    unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSObjectProtocol
99        for NSDictionary<KeyType, ObjectType>
100    {
101    }
102);
103
104#[cfg(feature = "NSObject")]
105extern_conformance!(
106    unsafe impl<KeyType: ?Sized + NSSecureCoding, ObjectType: ?Sized + NSSecureCoding>
107        NSSecureCoding for NSDictionary<KeyType, ObjectType>
108    {
109    }
110);
111
112impl<KeyType: Message, ObjectType: Message> NSDictionary<KeyType, ObjectType> {
113    extern_methods!(
114        #[unsafe(method(count))]
115        #[unsafe(method_family = none)]
116        pub fn count(&self) -> NSUInteger;
117
118        #[unsafe(method(objectForKey:))]
119        #[unsafe(method_family = none)]
120        pub fn objectForKey(&self, a_key: &KeyType) -> Option<Retained<ObjectType>>;
121
122        #[cfg(feature = "NSEnumerator")]
123        /// # Safety
124        ///
125        /// The returned enumerator's underlying collection should not be mutated while in use.
126        #[unsafe(method(keyEnumerator))]
127        #[unsafe(method_family = none)]
128        pub unsafe fn keyEnumerator(&self) -> Retained<NSEnumerator<KeyType>>;
129
130        #[unsafe(method(init))]
131        #[unsafe(method_family = init)]
132        pub fn init(this: Allocated<Self>) -> Retained<Self>;
133
134        #[cfg(feature = "NSObject")]
135        /// # Safety
136        ///
137        /// - `objects` must be a valid pointer or null.
138        /// - `keys` must be a valid pointer or null.
139        #[unsafe(method(initWithObjects:forKeys:count:))]
140        #[unsafe(method_family = init)]
141        pub unsafe fn initWithObjects_forKeys_count(
142            this: Allocated<Self>,
143            objects: *mut NonNull<ObjectType>,
144            keys: *mut NonNull<ProtocolObject<dyn NSCopying>>,
145            cnt: NSUInteger,
146        ) -> Retained<Self>;
147
148        #[cfg(feature = "NSCoder")]
149        /// # Safety
150        ///
151        /// `coder` possibly has further requirements.
152        #[unsafe(method(initWithCoder:))]
153        #[unsafe(method_family = init)]
154        pub unsafe fn initWithCoder(
155            this: Allocated<Self>,
156            coder: &NSCoder,
157        ) -> Option<Retained<Self>>;
158    );
159}
160
161/// Methods declared on superclass `NSObject`.
162impl<KeyType: Message, ObjectType: Message> NSDictionary<KeyType, ObjectType> {
163    extern_methods!(
164        #[unsafe(method(new))]
165        #[unsafe(method_family = new)]
166        pub fn new() -> Retained<Self>;
167    );
168}
169
170impl<KeyType: Message, ObjectType: Message> DefaultRetained for NSDictionary<KeyType, ObjectType> {
171    #[inline]
172    fn default_retained() -> Retained<Self> {
173        Self::new()
174    }
175}
176
177/// NSExtendedDictionary.
178impl<KeyType: Message, ObjectType: Message> NSDictionary<KeyType, ObjectType> {
179    extern_methods!(
180        #[cfg(feature = "NSArray")]
181        #[unsafe(method(allKeys))]
182        #[unsafe(method_family = none)]
183        pub fn allKeys(&self) -> Retained<NSArray<KeyType>>;
184
185        #[cfg(feature = "NSArray")]
186        #[unsafe(method(allKeysForObject:))]
187        #[unsafe(method_family = none)]
188        pub fn allKeysForObject(&self, an_object: &ObjectType) -> Retained<NSArray<KeyType>>;
189
190        #[cfg(feature = "NSArray")]
191        #[unsafe(method(allValues))]
192        #[unsafe(method_family = none)]
193        pub fn allValues(&self) -> Retained<NSArray<ObjectType>>;
194
195        #[cfg(feature = "NSString")]
196        #[unsafe(method(description))]
197        #[unsafe(method_family = none)]
198        pub fn description(&self) -> Retained<NSString>;
199
200        #[cfg(feature = "NSString")]
201        #[unsafe(method(descriptionInStringsFileFormat))]
202        #[unsafe(method_family = none)]
203        pub fn descriptionInStringsFileFormat(&self) -> Retained<NSString>;
204
205        #[cfg(feature = "NSString")]
206        /// # Safety
207        ///
208        /// `locale` should be of the correct type.
209        #[unsafe(method(descriptionWithLocale:))]
210        #[unsafe(method_family = none)]
211        pub unsafe fn descriptionWithLocale(
212            &self,
213            locale: Option<&AnyObject>,
214        ) -> Retained<NSString>;
215
216        #[cfg(feature = "NSString")]
217        /// # Safety
218        ///
219        /// `locale` should be of the correct type.
220        #[unsafe(method(descriptionWithLocale:indent:))]
221        #[unsafe(method_family = none)]
222        pub unsafe fn descriptionWithLocale_indent(
223            &self,
224            locale: Option<&AnyObject>,
225            level: NSUInteger,
226        ) -> Retained<NSString>;
227
228        #[unsafe(method(isEqualToDictionary:))]
229        #[unsafe(method_family = none)]
230        pub fn isEqualToDictionary(
231            &self,
232            other_dictionary: &NSDictionary<KeyType, ObjectType>,
233        ) -> bool;
234
235        #[cfg(feature = "NSEnumerator")]
236        /// # Safety
237        ///
238        /// The returned enumerator's underlying collection should not be mutated while in use.
239        #[unsafe(method(objectEnumerator))]
240        #[unsafe(method_family = none)]
241        pub unsafe fn objectEnumerator(&self) -> Retained<NSEnumerator<ObjectType>>;
242
243        #[cfg(feature = "NSArray")]
244        #[unsafe(method(objectsForKeys:notFoundMarker:))]
245        #[unsafe(method_family = none)]
246        pub fn objectsForKeys_notFoundMarker(
247            &self,
248            keys: &NSArray<KeyType>,
249            marker: &ObjectType,
250        ) -> Retained<NSArray<ObjectType>>;
251
252        #[cfg(all(feature = "NSError", feature = "NSURL"))]
253        #[unsafe(method(writeToURL:error:_))]
254        #[unsafe(method_family = none)]
255        pub unsafe fn writeToURL_error(&self, url: &NSURL) -> Result<(), Retained<NSError>>;
256
257        #[cfg(feature = "NSArray")]
258        /// # Safety
259        ///
260        /// `comparator` must be a valid selector.
261        #[unsafe(method(keysSortedByValueUsingSelector:))]
262        #[unsafe(method_family = none)]
263        pub unsafe fn keysSortedByValueUsingSelector(
264            &self,
265            comparator: Sel,
266        ) -> Retained<NSArray<KeyType>>;
267
268        /// # Safety
269        ///
270        /// - `objects` must be a valid pointer or null.
271        /// - `keys` must be a valid pointer or null.
272        #[unsafe(method(getObjects:andKeys:count:))]
273        #[unsafe(method_family = none)]
274        pub unsafe fn getObjects_andKeys_count(
275            &self,
276            objects: *mut NonNull<ObjectType>,
277            keys: *mut NonNull<KeyType>,
278            count: NSUInteger,
279        );
280
281        #[unsafe(method(objectForKeyedSubscript:))]
282        #[unsafe(method_family = none)]
283        pub fn objectForKeyedSubscript(&self, key: &KeyType) -> Option<Retained<ObjectType>>;
284
285        #[cfg(feature = "block2")]
286        #[unsafe(method(enumerateKeysAndObjectsUsingBlock:))]
287        #[unsafe(method_family = none)]
288        pub fn enumerateKeysAndObjectsUsingBlock(
289            &self,
290            block: &block2::DynBlock<
291                dyn Fn(NonNull<KeyType>, NonNull<ObjectType>, NonNull<Bool>) + '_,
292            >,
293        );
294
295        #[cfg(all(feature = "NSObjCRuntime", feature = "block2"))]
296        #[unsafe(method(enumerateKeysAndObjectsWithOptions:usingBlock:))]
297        #[unsafe(method_family = none)]
298        pub fn enumerateKeysAndObjectsWithOptions_usingBlock(
299            &self,
300            opts: NSEnumerationOptions,
301            block: &block2::DynBlock<
302                dyn Fn(NonNull<KeyType>, NonNull<ObjectType>, NonNull<Bool>) + '_,
303            >,
304        );
305
306        #[cfg(all(feature = "NSArray", feature = "NSObjCRuntime", feature = "block2"))]
307        /// # Safety
308        ///
309        /// `cmptr` must be a valid pointer.
310        #[unsafe(method(keysSortedByValueUsingComparator:))]
311        #[unsafe(method_family = none)]
312        pub unsafe fn keysSortedByValueUsingComparator(
313            &self,
314            cmptr: NSComparator,
315        ) -> Retained<NSArray<KeyType>>;
316
317        #[cfg(all(feature = "NSArray", feature = "NSObjCRuntime", feature = "block2"))]
318        /// # Safety
319        ///
320        /// `cmptr` must be a valid pointer.
321        #[unsafe(method(keysSortedByValueWithOptions:usingComparator:))]
322        #[unsafe(method_family = none)]
323        pub unsafe fn keysSortedByValueWithOptions_usingComparator(
324            &self,
325            opts: NSSortOptions,
326            cmptr: NSComparator,
327        ) -> Retained<NSArray<KeyType>>;
328
329        #[cfg(all(feature = "NSSet", feature = "block2"))]
330        #[unsafe(method(keysOfEntriesPassingTest:))]
331        #[unsafe(method_family = none)]
332        pub fn keysOfEntriesPassingTest(
333            &self,
334            predicate: &block2::DynBlock<
335                dyn Fn(NonNull<KeyType>, NonNull<ObjectType>, NonNull<Bool>) -> Bool + '_,
336            >,
337        ) -> Retained<NSSet<KeyType>>;
338
339        #[cfg(all(feature = "NSObjCRuntime", feature = "NSSet", feature = "block2"))]
340        #[unsafe(method(keysOfEntriesWithOptions:passingTest:))]
341        #[unsafe(method_family = none)]
342        pub fn keysOfEntriesWithOptions_passingTest(
343            &self,
344            opts: NSEnumerationOptions,
345            predicate: &block2::DynBlock<
346                dyn Fn(NonNull<KeyType>, NonNull<ObjectType>, NonNull<Bool>) -> Bool + '_,
347            >,
348        ) -> Retained<NSSet<KeyType>>;
349    );
350}
351
352/// NSDeprecated.
353impl<KeyType: Message, ObjectType: Message> NSDictionary<KeyType, ObjectType> {
354    extern_methods!(
355        /// This method is unsafe because it could potentially cause buffer overruns. You should use -getObjects:andKeys:count:
356        ///
357        /// # Safety
358        ///
359        /// - `objects` must be a valid pointer or null.
360        /// - `keys` must be a valid pointer or null.
361        #[deprecated = "Use -getObjects:andKeys:count: instead"]
362        #[unsafe(method(getObjects:andKeys:))]
363        #[unsafe(method_family = none)]
364        pub unsafe fn getObjects_andKeys(
365            &self,
366            objects: *mut NonNull<ObjectType>,
367            keys: *mut NonNull<KeyType>,
368        );
369
370        #[cfg(feature = "NSString")]
371        #[deprecated]
372        #[unsafe(method(dictionaryWithContentsOfFile:))]
373        #[unsafe(method_family = none)]
374        pub unsafe fn dictionaryWithContentsOfFile(
375            path: &NSString,
376        ) -> Option<Retained<NSDictionary<KeyType, ObjectType>>>;
377
378        #[cfg(feature = "NSURL")]
379        #[deprecated]
380        #[unsafe(method(dictionaryWithContentsOfURL:))]
381        #[unsafe(method_family = none)]
382        pub unsafe fn dictionaryWithContentsOfURL(
383            url: &NSURL,
384        ) -> Option<Retained<NSDictionary<KeyType, ObjectType>>>;
385
386        #[cfg(feature = "NSString")]
387        #[deprecated]
388        #[unsafe(method(initWithContentsOfFile:))]
389        #[unsafe(method_family = init)]
390        pub unsafe fn initWithContentsOfFile(
391            this: Allocated<Self>,
392            path: &NSString,
393        ) -> Option<Retained<NSDictionary<KeyType, ObjectType>>>;
394
395        #[cfg(feature = "NSURL")]
396        #[deprecated]
397        #[unsafe(method(initWithContentsOfURL:))]
398        #[unsafe(method_family = init)]
399        pub unsafe fn initWithContentsOfURL(
400            this: Allocated<Self>,
401            url: &NSURL,
402        ) -> Option<Retained<NSDictionary<KeyType, ObjectType>>>;
403
404        #[cfg(feature = "NSString")]
405        #[deprecated]
406        #[unsafe(method(writeToFile:atomically:))]
407        #[unsafe(method_family = none)]
408        pub unsafe fn writeToFile_atomically(
409            &self,
410            path: &NSString,
411            use_auxiliary_file: bool,
412        ) -> bool;
413
414        #[cfg(feature = "NSURL")]
415        #[deprecated]
416        #[unsafe(method(writeToURL:atomically:))]
417        #[unsafe(method_family = none)]
418        pub unsafe fn writeToURL_atomically(&self, url: &NSURL, atomically: bool) -> bool;
419    );
420}
421
422/// NSDictionaryCreation.
423impl<KeyType: Message, ObjectType: Message> NSDictionary<KeyType, ObjectType> {
424    extern_methods!(
425        #[unsafe(method(dictionary))]
426        #[unsafe(method_family = none)]
427        pub fn dictionary() -> Retained<Self>;
428
429        #[cfg(feature = "NSObject")]
430        /// # Safety
431        ///
432        /// `key` should be of the correct type.
433        #[unsafe(method(dictionaryWithObject:forKey:))]
434        #[unsafe(method_family = none)]
435        pub unsafe fn dictionaryWithObject_forKey(
436            object: &ObjectType,
437            key: &ProtocolObject<dyn NSCopying>,
438        ) -> Retained<Self>;
439
440        #[cfg(feature = "NSObject")]
441        /// # Safety
442        ///
443        /// - `objects` must be a valid pointer or null.
444        /// - `keys` must be a valid pointer or null.
445        #[unsafe(method(dictionaryWithObjects:forKeys:count:))]
446        #[unsafe(method_family = none)]
447        pub unsafe fn dictionaryWithObjects_forKeys_count(
448            objects: *mut NonNull<ObjectType>,
449            keys: *mut NonNull<ProtocolObject<dyn NSCopying>>,
450            cnt: NSUInteger,
451        ) -> Retained<Self>;
452
453        #[unsafe(method(dictionaryWithDictionary:))]
454        #[unsafe(method_family = none)]
455        pub fn dictionaryWithDictionary(dict: &NSDictionary<KeyType, ObjectType>)
456            -> Retained<Self>;
457
458        #[cfg(all(feature = "NSArray", feature = "NSObject"))]
459        /// # Safety
460        ///
461        /// `keys` generic should be of the correct type.
462        #[unsafe(method(dictionaryWithObjects:forKeys:))]
463        #[unsafe(method_family = none)]
464        pub unsafe fn dictionaryWithObjects_forKeys(
465            objects: &NSArray<ObjectType>,
466            keys: &NSArray<ProtocolObject<dyn NSCopying>>,
467        ) -> Retained<Self>;
468
469        #[unsafe(method(initWithDictionary:))]
470        #[unsafe(method_family = init)]
471        pub fn initWithDictionary(
472            this: Allocated<Self>,
473            other_dictionary: &NSDictionary<KeyType, ObjectType>,
474        ) -> Retained<Self>;
475
476        #[unsafe(method(initWithDictionary:copyItems:))]
477        #[unsafe(method_family = init)]
478        pub unsafe fn initWithDictionary_copyItems(
479            this: Allocated<Self>,
480            other_dictionary: &NSDictionary<KeyType, ObjectType>,
481            flag: bool,
482        ) -> Retained<Self>;
483
484        #[cfg(all(feature = "NSArray", feature = "NSObject"))]
485        /// # Safety
486        ///
487        /// `keys` generic should be of the correct type.
488        #[unsafe(method(initWithObjects:forKeys:))]
489        #[unsafe(method_family = init)]
490        pub unsafe fn initWithObjects_forKeys(
491            this: Allocated<Self>,
492            objects: &NSArray<ObjectType>,
493            keys: &NSArray<ProtocolObject<dyn NSCopying>>,
494        ) -> Retained<Self>;
495    );
496}
497
498/// Methods declared on superclass `NSDictionary`.
499///
500/// NSDictionaryCreation.
501impl<KeyType: Message, ObjectType: Message> NSMutableDictionary<KeyType, ObjectType> {
502    extern_methods!(
503        #[unsafe(method(dictionary))]
504        #[unsafe(method_family = none)]
505        pub fn dictionary() -> Retained<Self>;
506
507        #[cfg(feature = "NSObject")]
508        /// # Safety
509        ///
510        /// `key` should be of the correct type.
511        #[unsafe(method(dictionaryWithObject:forKey:))]
512        #[unsafe(method_family = none)]
513        pub unsafe fn dictionaryWithObject_forKey(
514            object: &ObjectType,
515            key: &ProtocolObject<dyn NSCopying>,
516        ) -> Retained<Self>;
517
518        #[cfg(feature = "NSObject")]
519        /// # Safety
520        ///
521        /// - `objects` must be a valid pointer or null.
522        /// - `keys` must be a valid pointer or null.
523        #[unsafe(method(dictionaryWithObjects:forKeys:count:))]
524        #[unsafe(method_family = none)]
525        pub unsafe fn dictionaryWithObjects_forKeys_count(
526            objects: *mut NonNull<ObjectType>,
527            keys: *mut NonNull<ProtocolObject<dyn NSCopying>>,
528            cnt: NSUInteger,
529        ) -> Retained<Self>;
530
531        #[unsafe(method(dictionaryWithDictionary:))]
532        #[unsafe(method_family = none)]
533        pub fn dictionaryWithDictionary(dict: &NSDictionary<KeyType, ObjectType>)
534            -> Retained<Self>;
535
536        #[cfg(all(feature = "NSArray", feature = "NSObject"))]
537        /// # Safety
538        ///
539        /// `keys` generic should be of the correct type.
540        #[unsafe(method(dictionaryWithObjects:forKeys:))]
541        #[unsafe(method_family = none)]
542        pub unsafe fn dictionaryWithObjects_forKeys(
543            objects: &NSArray<ObjectType>,
544            keys: &NSArray<ProtocolObject<dyn NSCopying>>,
545        ) -> Retained<Self>;
546
547        #[unsafe(method(initWithDictionary:))]
548        #[unsafe(method_family = init)]
549        pub fn initWithDictionary(
550            this: Allocated<Self>,
551            other_dictionary: &NSDictionary<KeyType, ObjectType>,
552        ) -> Retained<Self>;
553
554        #[unsafe(method(initWithDictionary:copyItems:))]
555        #[unsafe(method_family = init)]
556        pub unsafe fn initWithDictionary_copyItems(
557            this: Allocated<Self>,
558            other_dictionary: &NSDictionary<KeyType, ObjectType>,
559            flag: bool,
560        ) -> Retained<Self>;
561
562        #[cfg(all(feature = "NSArray", feature = "NSObject"))]
563        /// # Safety
564        ///
565        /// `keys` generic should be of the correct type.
566        #[unsafe(method(initWithObjects:forKeys:))]
567        #[unsafe(method_family = init)]
568        pub unsafe fn initWithObjects_forKeys(
569            this: Allocated<Self>,
570            objects: &NSArray<ObjectType>,
571            keys: &NSArray<ProtocolObject<dyn NSCopying>>,
572        ) -> Retained<Self>;
573    );
574}
575
576extern_class!(
577    /// **************    Mutable Dictionary    ***************
578    ///
579    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsmutabledictionary?language=objc)
580    #[unsafe(super(NSDictionary<KeyType, ObjectType>, NSObject))]
581    #[derive(PartialEq, Eq, Hash)]
582    pub struct NSMutableDictionary<KeyType: ?Sized = AnyObject, ObjectType: ?Sized = AnyObject>;
583);
584
585#[cfg(feature = "objc2-core-foundation")]
586impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message>
587    AsRef<NSMutableDictionary<KeyType, ObjectType>> for CFMutableDictionary<KeyType, ObjectType>
588{
589    #[inline]
590    fn as_ref(&self) -> &NSMutableDictionary<KeyType, ObjectType> {
591        unsafe { &*((self as *const Self).cast()) }
592    }
593}
594
595#[cfg(feature = "objc2-core-foundation")]
596impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message>
597    AsRef<CFMutableDictionary<KeyType, ObjectType>> for NSMutableDictionary<KeyType, ObjectType>
598{
599    #[inline]
600    fn as_ref(&self) -> &CFMutableDictionary<KeyType, ObjectType> {
601        unsafe { &*((self as *const Self).cast()) }
602    }
603}
604
605impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message>
606    NSMutableDictionary<KeyType, ObjectType>
607{
608    /// Unchecked conversion of the generic parameters.
609    ///
610    /// # Safety
611    ///
612    /// The generics must be valid to reinterpret as the given types.
613    #[inline]
614    pub unsafe fn cast_unchecked<NewKeyType: ?Sized + Message, NewObjectType: ?Sized + Message>(
615        &self,
616    ) -> &NSMutableDictionary<NewKeyType, NewObjectType> {
617        unsafe { &*((self as *const Self).cast()) }
618    }
619}
620
621#[cfg(feature = "NSObject")]
622extern_conformance!(
623    unsafe impl<KeyType: ?Sized + NSCoding, ObjectType: ?Sized + NSCoding> NSCoding
624        for NSMutableDictionary<KeyType, ObjectType>
625    {
626    }
627);
628
629#[cfg(feature = "NSObject")]
630extern_conformance!(
631    unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSCopying
632        for NSMutableDictionary<KeyType, ObjectType>
633    {
634    }
635);
636
637#[cfg(feature = "NSObject")]
638unsafe impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message> CopyingHelper
639    for NSMutableDictionary<KeyType, ObjectType>
640{
641    type Result = NSDictionary<KeyType, ObjectType>;
642}
643
644#[cfg(feature = "NSEnumerator")]
645extern_conformance!(
646    unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSFastEnumeration
647        for NSMutableDictionary<KeyType, ObjectType>
648    {
649    }
650);
651
652#[cfg(feature = "NSObject")]
653extern_conformance!(
654    unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSMutableCopying
655        for NSMutableDictionary<KeyType, ObjectType>
656    {
657    }
658);
659
660#[cfg(feature = "NSObject")]
661unsafe impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message> MutableCopyingHelper
662    for NSMutableDictionary<KeyType, ObjectType>
663{
664    type Result = Self;
665}
666
667extern_conformance!(
668    unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSObjectProtocol
669        for NSMutableDictionary<KeyType, ObjectType>
670    {
671    }
672);
673
674#[cfg(feature = "NSObject")]
675extern_conformance!(
676    unsafe impl<KeyType: ?Sized + NSSecureCoding, ObjectType: ?Sized + NSSecureCoding>
677        NSSecureCoding for NSMutableDictionary<KeyType, ObjectType>
678    {
679    }
680);
681
682impl<KeyType: Message, ObjectType: Message> NSMutableDictionary<KeyType, ObjectType> {
683    extern_methods!(
684        #[unsafe(method(removeObjectForKey:))]
685        #[unsafe(method_family = none)]
686        pub fn removeObjectForKey(&self, a_key: &KeyType);
687
688        #[cfg(feature = "NSObject")]
689        /// # Safety
690        ///
691        /// `a_key` should be of the correct type.
692        #[unsafe(method(setObject:forKey:))]
693        #[unsafe(method_family = none)]
694        pub unsafe fn setObject_forKey(
695            &self,
696            an_object: &ObjectType,
697            a_key: &ProtocolObject<dyn NSCopying>,
698        );
699
700        #[unsafe(method(init))]
701        #[unsafe(method_family = init)]
702        pub fn init(this: Allocated<Self>) -> Retained<Self>;
703
704        #[unsafe(method(initWithCapacity:))]
705        #[unsafe(method_family = init)]
706        pub fn initWithCapacity(this: Allocated<Self>, num_items: NSUInteger) -> Retained<Self>;
707
708        #[cfg(feature = "NSCoder")]
709        /// # Safety
710        ///
711        /// `coder` possibly has further requirements.
712        #[unsafe(method(initWithCoder:))]
713        #[unsafe(method_family = init)]
714        pub unsafe fn initWithCoder(
715            this: Allocated<Self>,
716            coder: &NSCoder,
717        ) -> Option<Retained<Self>>;
718    );
719}
720
721/// Methods declared on superclass `NSDictionary`.
722impl<KeyType: Message, ObjectType: Message> NSMutableDictionary<KeyType, ObjectType> {
723    extern_methods!(
724        #[cfg(feature = "NSObject")]
725        /// # Safety
726        ///
727        /// - `objects` must be a valid pointer or null.
728        /// - `keys` must be a valid pointer or null.
729        #[unsafe(method(initWithObjects:forKeys:count:))]
730        #[unsafe(method_family = init)]
731        pub unsafe fn initWithObjects_forKeys_count(
732            this: Allocated<Self>,
733            objects: *mut NonNull<ObjectType>,
734            keys: *mut NonNull<ProtocolObject<dyn NSCopying>>,
735            cnt: NSUInteger,
736        ) -> Retained<Self>;
737    );
738}
739
740/// Methods declared on superclass `NSObject`.
741impl<KeyType: Message, ObjectType: Message> NSMutableDictionary<KeyType, ObjectType> {
742    extern_methods!(
743        #[unsafe(method(new))]
744        #[unsafe(method_family = new)]
745        pub fn new() -> Retained<Self>;
746    );
747}
748
749impl<KeyType: Message, ObjectType: Message> DefaultRetained
750    for NSMutableDictionary<KeyType, ObjectType>
751{
752    #[inline]
753    fn default_retained() -> Retained<Self> {
754        Self::new()
755    }
756}
757
758/// NSExtendedMutableDictionary.
759impl<KeyType: Message, ObjectType: Message> NSMutableDictionary<KeyType, ObjectType> {
760    extern_methods!(
761        #[unsafe(method(addEntriesFromDictionary:))]
762        #[unsafe(method_family = none)]
763        pub fn addEntriesFromDictionary(
764            &self,
765            other_dictionary: &NSDictionary<KeyType, ObjectType>,
766        );
767
768        #[unsafe(method(removeAllObjects))]
769        #[unsafe(method_family = none)]
770        pub fn removeAllObjects(&self);
771
772        #[cfg(feature = "NSArray")]
773        #[unsafe(method(removeObjectsForKeys:))]
774        #[unsafe(method_family = none)]
775        pub fn removeObjectsForKeys(&self, key_array: &NSArray<KeyType>);
776
777        #[unsafe(method(setDictionary:))]
778        #[unsafe(method_family = none)]
779        pub fn setDictionary(&self, other_dictionary: &NSDictionary<KeyType, ObjectType>);
780
781        #[cfg(feature = "NSObject")]
782        /// # Safety
783        ///
784        /// `key` should be of the correct type.
785        #[unsafe(method(setObject:forKeyedSubscript:))]
786        #[unsafe(method_family = none)]
787        pub unsafe fn setObject_forKeyedSubscript(
788            &self,
789            obj: Option<&ObjectType>,
790            key: &ProtocolObject<dyn NSCopying>,
791        );
792    );
793}
794
795/// NSMutableDictionaryCreation.
796impl<KeyType: Message, ObjectType: Message> NSMutableDictionary<KeyType, ObjectType> {
797    extern_methods!(
798        #[unsafe(method(dictionaryWithCapacity:))]
799        #[unsafe(method_family = none)]
800        pub fn dictionaryWithCapacity(num_items: NSUInteger) -> Retained<Self>;
801
802        #[cfg(feature = "NSString")]
803        #[unsafe(method(dictionaryWithContentsOfFile:))]
804        #[unsafe(method_family = none)]
805        pub unsafe fn dictionaryWithContentsOfFile(
806            path: &NSString,
807        ) -> Option<Retained<NSMutableDictionary<KeyType, ObjectType>>>;
808
809        #[cfg(feature = "NSURL")]
810        #[unsafe(method(dictionaryWithContentsOfURL:))]
811        #[unsafe(method_family = none)]
812        pub unsafe fn dictionaryWithContentsOfURL(
813            url: &NSURL,
814        ) -> Option<Retained<NSMutableDictionary<KeyType, ObjectType>>>;
815
816        #[cfg(feature = "NSString")]
817        #[unsafe(method(initWithContentsOfFile:))]
818        #[unsafe(method_family = init)]
819        pub unsafe fn initWithContentsOfFile(
820            this: Allocated<Self>,
821            path: &NSString,
822        ) -> Option<Retained<NSMutableDictionary<KeyType, ObjectType>>>;
823
824        #[cfg(feature = "NSURL")]
825        #[unsafe(method(initWithContentsOfURL:))]
826        #[unsafe(method_family = init)]
827        pub unsafe fn initWithContentsOfURL(
828            this: Allocated<Self>,
829            url: &NSURL,
830        ) -> Option<Retained<NSMutableDictionary<KeyType, ObjectType>>>;
831    );
832}
833
834/// NSSharedKeySetDictionary.
835impl<KeyType: Message, ObjectType: Message> NSDictionary<KeyType, ObjectType> {
836    extern_methods!(
837        #[cfg(all(feature = "NSArray", feature = "NSObject"))]
838        /// # Safety
839        ///
840        /// `keys` generic should be of the correct type.
841        #[unsafe(method(sharedKeySetForKeys:))]
842        #[unsafe(method_family = none)]
843        pub unsafe fn sharedKeySetForKeys(
844            keys: &NSArray<ProtocolObject<dyn NSCopying>>,
845        ) -> Retained<AnyObject>;
846    );
847}
848
849/// NSSharedKeySetDictionary.
850impl<KeyType: Message, ObjectType: Message> NSMutableDictionary<KeyType, ObjectType> {
851    extern_methods!(
852        /// # Safety
853        ///
854        /// `keyset` should be of the correct type.
855        #[unsafe(method(dictionaryWithSharedKeySet:))]
856        #[unsafe(method_family = none)]
857        pub unsafe fn dictionaryWithSharedKeySet(
858            keyset: &AnyObject,
859        ) -> Retained<NSMutableDictionary<KeyType, ObjectType>>;
860    );
861}