1use 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 #[unsafe(super(NSObject))]
16 #[derive(PartialEq, Eq, Hash)]
17 pub struct NSArray<ObjectType: ?Sized = AnyObject>;
18);
19
20#[cfg(feature = "objc2-core-foundation")]
21impl<ObjectType: ?Sized + Message> AsRef<NSArray<ObjectType>> for CFArray<ObjectType> {
22 #[inline]
23 fn as_ref(&self) -> &NSArray<ObjectType> {
24 unsafe { &*((self as *const Self).cast()) }
25 }
26}
27
28#[cfg(feature = "objc2-core-foundation")]
29impl<ObjectType: ?Sized + Message> AsRef<CFArray<ObjectType>> for NSArray<ObjectType> {
30 #[inline]
31 fn as_ref(&self) -> &CFArray<ObjectType> {
32 unsafe { &*((self as *const Self).cast()) }
33 }
34}
35
36impl<ObjectType: ?Sized + Message> NSArray<ObjectType> {
37 #[inline]
43 pub unsafe fn cast_unchecked<NewObjectType: ?Sized + Message>(
44 &self,
45 ) -> &NSArray<NewObjectType> {
46 unsafe { &*((self as *const Self).cast()) }
47 }
48}
49
50#[cfg(feature = "NSObject")]
51extern_conformance!(
52 unsafe impl<ObjectType: ?Sized + NSCoding> NSCoding for NSArray<ObjectType> {}
53);
54
55#[cfg(feature = "NSObject")]
56extern_conformance!(
57 unsafe impl<ObjectType: ?Sized> NSCopying for NSArray<ObjectType> {}
58);
59
60#[cfg(feature = "NSObject")]
61unsafe impl<ObjectType: ?Sized + Message> CopyingHelper for NSArray<ObjectType> {
62 type Result = Self;
63}
64
65#[cfg(feature = "NSEnumerator")]
66extern_conformance!(
67 unsafe impl<ObjectType: ?Sized> NSFastEnumeration for NSArray<ObjectType> {}
68);
69
70#[cfg(feature = "NSObject")]
71extern_conformance!(
72 unsafe impl<ObjectType: ?Sized> NSMutableCopying for NSArray<ObjectType> {}
73);
74
75#[cfg(feature = "NSObject")]
76unsafe impl<ObjectType: ?Sized + Message> MutableCopyingHelper for NSArray<ObjectType> {
77 type Result = NSMutableArray<ObjectType>;
78}
79
80extern_conformance!(
81 unsafe impl<ObjectType: ?Sized> NSObjectProtocol for NSArray<ObjectType> {}
82);
83
84#[cfg(feature = "NSObject")]
85extern_conformance!(
86 unsafe impl<ObjectType: ?Sized + NSSecureCoding> NSSecureCoding for NSArray<ObjectType> {}
87);
88
89impl<ObjectType: Message> NSArray<ObjectType> {
90 extern_methods!(
91 #[unsafe(method(count))]
92 #[unsafe(method_family = none)]
93 pub fn count(&self) -> NSUInteger;
94
95 #[unsafe(method(objectAtIndex:))]
96 #[unsafe(method_family = none)]
97 pub fn objectAtIndex(&self, index: NSUInteger) -> Retained<ObjectType>;
98
99 #[unsafe(method(init))]
100 #[unsafe(method_family = init)]
101 pub fn init(this: Allocated<Self>) -> Retained<Self>;
102
103 #[unsafe(method(initWithObjects:count:))]
107 #[unsafe(method_family = init)]
108 pub unsafe fn initWithObjects_count(
109 this: Allocated<Self>,
110 objects: *mut NonNull<ObjectType>,
111 cnt: NSUInteger,
112 ) -> Retained<Self>;
113
114 #[cfg(feature = "NSCoder")]
115 #[unsafe(method(initWithCoder:))]
119 #[unsafe(method_family = init)]
120 pub unsafe fn initWithCoder(
121 this: Allocated<Self>,
122 coder: &NSCoder,
123 ) -> Option<Retained<Self>>;
124 );
125}
126
127impl<ObjectType: Message> NSArray<ObjectType> {
129 extern_methods!(
130 #[unsafe(method(new))]
131 #[unsafe(method_family = new)]
132 pub fn new() -> Retained<Self>;
133 );
134}
135
136impl<ObjectType: Message> DefaultRetained for NSArray<ObjectType> {
137 #[inline]
138 fn default_retained() -> Retained<Self> {
139 Self::new()
140 }
141}
142
143#[repr(transparent)]
146#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
147pub struct NSBinarySearchingOptions(pub NSUInteger);
148bitflags::bitflags! {
149 impl NSBinarySearchingOptions: NSUInteger {
150 #[doc(alias = "NSBinarySearchingFirstEqual")]
151 const FirstEqual = 1<<8;
152 #[doc(alias = "NSBinarySearchingLastEqual")]
153 const LastEqual = 1<<9;
154 #[doc(alias = "NSBinarySearchingInsertionIndex")]
155 const InsertionIndex = 1<<10;
156 }
157}
158
159unsafe impl Encode for NSBinarySearchingOptions {
160 const ENCODING: Encoding = NSUInteger::ENCODING;
161}
162
163unsafe impl RefEncode for NSBinarySearchingOptions {
164 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
165}
166
167impl<ObjectType: Message> NSArray<ObjectType> {
169 extern_methods!(
170 #[unsafe(method(arrayByAddingObject:))]
171 #[unsafe(method_family = none)]
172 pub fn arrayByAddingObject(&self, an_object: &ObjectType) -> Retained<NSArray<ObjectType>>;
173
174 #[unsafe(method(arrayByAddingObjectsFromArray:))]
175 #[unsafe(method_family = none)]
176 pub fn arrayByAddingObjectsFromArray(
177 &self,
178 other_array: &NSArray<ObjectType>,
179 ) -> Retained<NSArray<ObjectType>>;
180
181 #[cfg(feature = "NSString")]
182 #[unsafe(method(componentsJoinedByString:))]
183 #[unsafe(method_family = none)]
184 pub fn componentsJoinedByString(&self, separator: &NSString) -> Retained<NSString>;
185
186 #[unsafe(method(containsObject:))]
187 #[unsafe(method_family = none)]
188 pub fn containsObject(&self, an_object: &ObjectType) -> bool;
189
190 #[cfg(feature = "NSString")]
191 #[unsafe(method(description))]
192 #[unsafe(method_family = none)]
193 pub fn description(&self) -> Retained<NSString>;
194
195 #[cfg(feature = "NSString")]
196 #[unsafe(method(descriptionWithLocale:))]
200 #[unsafe(method_family = none)]
201 pub unsafe fn descriptionWithLocale(
202 &self,
203 locale: Option<&AnyObject>,
204 ) -> Retained<NSString>;
205
206 #[cfg(feature = "NSString")]
207 #[unsafe(method(descriptionWithLocale:indent:))]
211 #[unsafe(method_family = none)]
212 pub unsafe fn descriptionWithLocale_indent(
213 &self,
214 locale: Option<&AnyObject>,
215 level: NSUInteger,
216 ) -> Retained<NSString>;
217
218 #[unsafe(method(firstObjectCommonWithArray:))]
219 #[unsafe(method_family = none)]
220 pub fn firstObjectCommonWithArray(
221 &self,
222 other_array: &NSArray<ObjectType>,
223 ) -> Option<Retained<ObjectType>>;
224
225 #[cfg(feature = "NSRange")]
226 #[unsafe(method(getObjects:range:))]
230 #[unsafe(method_family = none)]
231 pub unsafe fn getObjects_range(
232 &self,
233 objects: NonNull<NonNull<ObjectType>>,
234 range: NSRange,
235 );
236
237 #[unsafe(method(indexOfObject:))]
238 #[unsafe(method_family = none)]
239 pub fn indexOfObject(&self, an_object: &ObjectType) -> NSUInteger;
240
241 #[cfg(feature = "NSRange")]
242 #[unsafe(method(indexOfObject:inRange:))]
243 #[unsafe(method_family = none)]
244 pub fn indexOfObject_inRange(&self, an_object: &ObjectType, range: NSRange) -> NSUInteger;
245
246 #[unsafe(method(indexOfObjectIdenticalTo:))]
247 #[unsafe(method_family = none)]
248 pub fn indexOfObjectIdenticalTo(&self, an_object: &ObjectType) -> NSUInteger;
249
250 #[cfg(feature = "NSRange")]
251 #[unsafe(method(indexOfObjectIdenticalTo:inRange:))]
252 #[unsafe(method_family = none)]
253 pub fn indexOfObjectIdenticalTo_inRange(
254 &self,
255 an_object: &ObjectType,
256 range: NSRange,
257 ) -> NSUInteger;
258
259 #[unsafe(method(isEqualToArray:))]
260 #[unsafe(method_family = none)]
261 pub fn isEqualToArray(&self, other_array: &NSArray<ObjectType>) -> bool;
262
263 #[unsafe(method(firstObject))]
264 #[unsafe(method_family = none)]
265 pub fn firstObject(&self) -> Option<Retained<ObjectType>>;
266
267 #[unsafe(method(lastObject))]
268 #[unsafe(method_family = none)]
269 pub fn lastObject(&self) -> Option<Retained<ObjectType>>;
270
271 #[cfg(feature = "NSEnumerator")]
272 #[unsafe(method(objectEnumerator))]
276 #[unsafe(method_family = none)]
277 pub unsafe fn objectEnumerator(&self) -> Retained<NSEnumerator<ObjectType>>;
278
279 #[cfg(feature = "NSEnumerator")]
280 #[unsafe(method(reverseObjectEnumerator))]
284 #[unsafe(method_family = none)]
285 pub unsafe fn reverseObjectEnumerator(&self) -> Retained<NSEnumerator<ObjectType>>;
286
287 #[cfg(feature = "NSData")]
288 #[unsafe(method(sortedArrayHint))]
289 #[unsafe(method_family = none)]
290 pub fn sortedArrayHint(&self) -> Retained<NSData>;
291
292 #[unsafe(method(sortedArrayUsingFunction:context:))]
297 #[unsafe(method_family = none)]
298 pub unsafe fn sortedArrayUsingFunction_context(
299 &self,
300 comparator: unsafe extern "C-unwind" fn(
301 NonNull<ObjectType>,
302 NonNull<ObjectType>,
303 *mut c_void,
304 ) -> NSInteger,
305 context: *mut c_void,
306 ) -> Retained<NSArray<ObjectType>>;
307
308 #[cfg(feature = "NSData")]
309 #[unsafe(method(sortedArrayUsingFunction:context:hint:))]
314 #[unsafe(method_family = none)]
315 pub unsafe fn sortedArrayUsingFunction_context_hint(
316 &self,
317 comparator: unsafe extern "C-unwind" fn(
318 NonNull<ObjectType>,
319 NonNull<ObjectType>,
320 *mut c_void,
321 ) -> NSInteger,
322 context: *mut c_void,
323 hint: Option<&NSData>,
324 ) -> Retained<NSArray<ObjectType>>;
325
326 #[unsafe(method(sortedArrayUsingSelector:))]
330 #[unsafe(method_family = none)]
331 pub unsafe fn sortedArrayUsingSelector(
332 &self,
333 comparator: Sel,
334 ) -> Retained<NSArray<ObjectType>>;
335
336 #[cfg(feature = "NSRange")]
337 #[unsafe(method(subarrayWithRange:))]
338 #[unsafe(method_family = none)]
339 pub fn subarrayWithRange(&self, range: NSRange) -> Retained<NSArray<ObjectType>>;
340
341 #[cfg(all(feature = "NSError", feature = "NSURL"))]
342 #[unsafe(method(writeToURL:error:_))]
343 #[unsafe(method_family = none)]
344 pub unsafe fn writeToURL_error(&self, url: &NSURL) -> Result<(), Retained<NSError>>;
345
346 #[unsafe(method(makeObjectsPerformSelector:))]
350 #[unsafe(method_family = none)]
351 pub unsafe fn makeObjectsPerformSelector(&self, a_selector: Sel);
352
353 #[unsafe(method(makeObjectsPerformSelector:withObject:))]
358 #[unsafe(method_family = none)]
359 pub unsafe fn makeObjectsPerformSelector_withObject(
360 &self,
361 a_selector: Sel,
362 argument: Option<&AnyObject>,
363 );
364
365 #[cfg(feature = "NSIndexSet")]
366 #[unsafe(method(objectsAtIndexes:))]
367 #[unsafe(method_family = none)]
368 pub fn objectsAtIndexes(&self, indexes: &NSIndexSet) -> Retained<NSArray<ObjectType>>;
369
370 #[unsafe(method(objectAtIndexedSubscript:))]
371 #[unsafe(method_family = none)]
372 pub fn objectAtIndexedSubscript(&self, idx: NSUInteger) -> Retained<ObjectType>;
373
374 #[cfg(feature = "block2")]
375 #[unsafe(method(enumerateObjectsUsingBlock:))]
376 #[unsafe(method_family = none)]
377 pub fn enumerateObjectsUsingBlock(
378 &self,
379 block: &block2::DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) + '_>,
380 );
381
382 #[cfg(all(feature = "NSObjCRuntime", feature = "block2"))]
383 #[unsafe(method(enumerateObjectsWithOptions:usingBlock:))]
384 #[unsafe(method_family = none)]
385 pub fn enumerateObjectsWithOptions_usingBlock(
386 &self,
387 opts: NSEnumerationOptions,
388 block: &block2::DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) + '_>,
389 );
390
391 #[cfg(all(feature = "NSIndexSet", feature = "NSObjCRuntime", feature = "block2"))]
392 #[unsafe(method(enumerateObjectsAtIndexes:options:usingBlock:))]
393 #[unsafe(method_family = none)]
394 pub fn enumerateObjectsAtIndexes_options_usingBlock(
395 &self,
396 s: &NSIndexSet,
397 opts: NSEnumerationOptions,
398 block: &block2::DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) + '_>,
399 );
400
401 #[cfg(feature = "block2")]
402 #[unsafe(method(indexOfObjectPassingTest:))]
403 #[unsafe(method_family = none)]
404 pub fn indexOfObjectPassingTest(
405 &self,
406 predicate: &block2::DynBlock<
407 dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_,
408 >,
409 ) -> NSUInteger;
410
411 #[cfg(all(feature = "NSObjCRuntime", feature = "block2"))]
412 #[unsafe(method(indexOfObjectWithOptions:passingTest:))]
413 #[unsafe(method_family = none)]
414 pub fn indexOfObjectWithOptions_passingTest(
415 &self,
416 opts: NSEnumerationOptions,
417 predicate: &block2::DynBlock<
418 dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_,
419 >,
420 ) -> NSUInteger;
421
422 #[cfg(all(feature = "NSIndexSet", feature = "NSObjCRuntime", feature = "block2"))]
423 #[unsafe(method(indexOfObjectAtIndexes:options:passingTest:))]
424 #[unsafe(method_family = none)]
425 pub fn indexOfObjectAtIndexes_options_passingTest(
426 &self,
427 s: &NSIndexSet,
428 opts: NSEnumerationOptions,
429 predicate: &block2::DynBlock<
430 dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_,
431 >,
432 ) -> NSUInteger;
433
434 #[cfg(all(feature = "NSIndexSet", feature = "block2"))]
435 #[unsafe(method(indexesOfObjectsPassingTest:))]
436 #[unsafe(method_family = none)]
437 pub fn indexesOfObjectsPassingTest(
438 &self,
439 predicate: &block2::DynBlock<
440 dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_,
441 >,
442 ) -> Retained<NSIndexSet>;
443
444 #[cfg(all(feature = "NSIndexSet", feature = "NSObjCRuntime", feature = "block2"))]
445 #[unsafe(method(indexesOfObjectsWithOptions:passingTest:))]
446 #[unsafe(method_family = none)]
447 pub fn indexesOfObjectsWithOptions_passingTest(
448 &self,
449 opts: NSEnumerationOptions,
450 predicate: &block2::DynBlock<
451 dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_,
452 >,
453 ) -> Retained<NSIndexSet>;
454
455 #[cfg(all(feature = "NSIndexSet", feature = "NSObjCRuntime", feature = "block2"))]
456 #[unsafe(method(indexesOfObjectsAtIndexes:options:passingTest:))]
457 #[unsafe(method_family = none)]
458 pub fn indexesOfObjectsAtIndexes_options_passingTest(
459 &self,
460 s: &NSIndexSet,
461 opts: NSEnumerationOptions,
462 predicate: &block2::DynBlock<
463 dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_,
464 >,
465 ) -> Retained<NSIndexSet>;
466
467 #[cfg(all(feature = "NSObjCRuntime", feature = "block2"))]
468 #[unsafe(method(sortedArrayUsingComparator:))]
472 #[unsafe(method_family = none)]
473 pub unsafe fn sortedArrayUsingComparator(
474 &self,
475 cmptr: NSComparator,
476 ) -> Retained<NSArray<ObjectType>>;
477
478 #[cfg(all(feature = "NSObjCRuntime", feature = "block2"))]
479 #[unsafe(method(sortedArrayWithOptions:usingComparator:))]
483 #[unsafe(method_family = none)]
484 pub unsafe fn sortedArrayWithOptions_usingComparator(
485 &self,
486 opts: NSSortOptions,
487 cmptr: NSComparator,
488 ) -> Retained<NSArray<ObjectType>>;
489
490 #[cfg(all(feature = "NSObjCRuntime", feature = "NSRange", feature = "block2"))]
491 #[unsafe(method(indexOfObject:inSortedRange:options:usingComparator:))]
495 #[unsafe(method_family = none)]
496 pub unsafe fn indexOfObject_inSortedRange_options_usingComparator(
497 &self,
498 obj: &ObjectType,
499 r: NSRange,
500 opts: NSBinarySearchingOptions,
501 cmp: NSComparator,
502 ) -> NSUInteger;
503 );
504}
505
506impl<ObjectType: Message> NSArray<ObjectType> {
508 extern_methods!(
509 #[unsafe(method(array))]
510 #[unsafe(method_family = none)]
511 pub fn array() -> Retained<Self>;
512
513 #[unsafe(method(arrayWithObject:))]
514 #[unsafe(method_family = none)]
515 pub fn arrayWithObject(an_object: &ObjectType) -> Retained<Self>;
516
517 #[unsafe(method(arrayWithObjects:count:))]
521 #[unsafe(method_family = none)]
522 pub unsafe fn arrayWithObjects_count(
523 objects: NonNull<NonNull<ObjectType>>,
524 cnt: NSUInteger,
525 ) -> Retained<Self>;
526
527 #[unsafe(method(arrayWithArray:))]
528 #[unsafe(method_family = none)]
529 pub fn arrayWithArray(array: &NSArray<ObjectType>) -> Retained<Self>;
530
531 #[unsafe(method(initWithArray:))]
532 #[unsafe(method_family = init)]
533 pub fn initWithArray(this: Allocated<Self>, array: &NSArray<ObjectType>) -> Retained<Self>;
534
535 #[unsafe(method(initWithArray:copyItems:))]
536 #[unsafe(method_family = init)]
537 pub unsafe fn initWithArray_copyItems(
538 this: Allocated<Self>,
539 array: &NSArray<ObjectType>,
540 flag: bool,
541 ) -> Retained<Self>;
542
543 #[cfg(all(feature = "NSError", feature = "NSURL"))]
544 #[unsafe(method(initWithContentsOfURL:error:_))]
545 #[unsafe(method_family = init)]
546 pub unsafe fn initWithContentsOfURL_error(
547 this: Allocated<Self>,
548 url: &NSURL,
549 ) -> Result<Retained<NSArray<ObjectType>>, Retained<NSError>>;
550
551 #[cfg(all(feature = "NSError", feature = "NSURL"))]
552 #[unsafe(method(arrayWithContentsOfURL:error:_))]
553 #[unsafe(method_family = none)]
554 pub unsafe fn arrayWithContentsOfURL_error(
555 url: &NSURL,
556 ) -> Result<Retained<NSArray<ObjectType>>, Retained<NSError>>;
557 );
558}
559
560impl<ObjectType: Message> NSMutableArray<ObjectType> {
564 extern_methods!(
565 #[unsafe(method(array))]
566 #[unsafe(method_family = none)]
567 pub fn array() -> Retained<Self>;
568
569 #[unsafe(method(arrayWithObject:))]
570 #[unsafe(method_family = none)]
571 pub fn arrayWithObject(an_object: &ObjectType) -> Retained<Self>;
572
573 #[unsafe(method(arrayWithObjects:count:))]
577 #[unsafe(method_family = none)]
578 pub unsafe fn arrayWithObjects_count(
579 objects: NonNull<NonNull<ObjectType>>,
580 cnt: NSUInteger,
581 ) -> Retained<Self>;
582
583 #[unsafe(method(arrayWithArray:))]
584 #[unsafe(method_family = none)]
585 pub fn arrayWithArray(array: &NSArray<ObjectType>) -> Retained<Self>;
586
587 #[unsafe(method(initWithArray:))]
588 #[unsafe(method_family = init)]
589 pub fn initWithArray(this: Allocated<Self>, array: &NSArray<ObjectType>) -> Retained<Self>;
590
591 #[unsafe(method(initWithArray:copyItems:))]
592 #[unsafe(method_family = init)]
593 pub unsafe fn initWithArray_copyItems(
594 this: Allocated<Self>,
595 array: &NSArray<ObjectType>,
596 flag: bool,
597 ) -> Retained<Self>;
598 );
599}
600
601impl<ObjectType: Message> NSArray<ObjectType> {
603 extern_methods!(
604 #[cfg(all(feature = "NSOrderedCollectionDifference", feature = "block2"))]
605 #[unsafe(method(differenceFromArray:withOptions:usingEquivalenceTest:))]
606 #[unsafe(method_family = none)]
607 pub fn differenceFromArray_withOptions_usingEquivalenceTest(
608 &self,
609 other: &NSArray<ObjectType>,
610 options: NSOrderedCollectionDifferenceCalculationOptions,
611 block: &block2::DynBlock<dyn Fn(NonNull<ObjectType>, NonNull<ObjectType>) -> Bool + '_>,
612 ) -> Retained<NSOrderedCollectionDifference<ObjectType>>;
613
614 #[cfg(feature = "NSOrderedCollectionDifference")]
615 #[unsafe(method(differenceFromArray:withOptions:))]
616 #[unsafe(method_family = none)]
617 pub fn differenceFromArray_withOptions(
618 &self,
619 other: &NSArray<ObjectType>,
620 options: NSOrderedCollectionDifferenceCalculationOptions,
621 ) -> Retained<NSOrderedCollectionDifference<ObjectType>>;
622
623 #[cfg(feature = "NSOrderedCollectionDifference")]
624 #[unsafe(method(differenceFromArray:))]
625 #[unsafe(method_family = none)]
626 pub fn differenceFromArray(
627 &self,
628 other: &NSArray<ObjectType>,
629 ) -> Retained<NSOrderedCollectionDifference<ObjectType>>;
630
631 #[cfg(feature = "NSOrderedCollectionDifference")]
632 #[unsafe(method(arrayByApplyingDifference:))]
633 #[unsafe(method_family = none)]
634 pub fn arrayByApplyingDifference(
635 &self,
636 difference: &NSOrderedCollectionDifference<ObjectType>,
637 ) -> Option<Retained<NSArray<ObjectType>>>;
638 );
639}
640
641impl<ObjectType: Message> NSArray<ObjectType> {
643 extern_methods!(
644 #[deprecated = "Use -getObjects:range: instead"]
648 #[unsafe(method(getObjects:))]
649 #[unsafe(method_family = none)]
650 pub unsafe fn getObjects(&self, objects: NonNull<NonNull<ObjectType>>);
651
652 #[cfg(feature = "NSString")]
653 #[deprecated]
654 #[unsafe(method(arrayWithContentsOfFile:))]
655 #[unsafe(method_family = none)]
656 pub unsafe fn arrayWithContentsOfFile(
657 path: &NSString,
658 ) -> Option<Retained<NSArray<ObjectType>>>;
659
660 #[cfg(feature = "NSURL")]
661 #[deprecated]
662 #[unsafe(method(arrayWithContentsOfURL:))]
663 #[unsafe(method_family = none)]
664 pub unsafe fn arrayWithContentsOfURL(url: &NSURL) -> Option<Retained<NSArray<ObjectType>>>;
665
666 #[cfg(feature = "NSString")]
667 #[deprecated]
668 #[unsafe(method(initWithContentsOfFile:))]
669 #[unsafe(method_family = init)]
670 pub unsafe fn initWithContentsOfFile(
671 this: Allocated<Self>,
672 path: &NSString,
673 ) -> Option<Retained<NSArray<ObjectType>>>;
674
675 #[cfg(feature = "NSURL")]
676 #[deprecated]
677 #[unsafe(method(initWithContentsOfURL:))]
678 #[unsafe(method_family = init)]
679 pub unsafe fn initWithContentsOfURL(
680 this: Allocated<Self>,
681 url: &NSURL,
682 ) -> Option<Retained<NSArray<ObjectType>>>;
683
684 #[cfg(feature = "NSString")]
685 #[deprecated]
686 #[unsafe(method(writeToFile:atomically:))]
687 #[unsafe(method_family = none)]
688 pub unsafe fn writeToFile_atomically(
689 &self,
690 path: &NSString,
691 use_auxiliary_file: bool,
692 ) -> bool;
693
694 #[cfg(feature = "NSURL")]
695 #[deprecated]
696 #[unsafe(method(writeToURL:atomically:))]
697 #[unsafe(method_family = none)]
698 pub unsafe fn writeToURL_atomically(&self, url: &NSURL, atomically: bool) -> bool;
699 );
700}
701
702extern_class!(
703 #[unsafe(super(NSArray<ObjectType>, NSObject))]
707 #[derive(PartialEq, Eq, Hash)]
708 pub struct NSMutableArray<ObjectType: ?Sized = AnyObject>;
709);
710
711#[cfg(feature = "objc2-core-foundation")]
712impl<ObjectType: ?Sized + Message> AsRef<NSMutableArray<ObjectType>>
713 for CFMutableArray<ObjectType>
714{
715 #[inline]
716 fn as_ref(&self) -> &NSMutableArray<ObjectType> {
717 unsafe { &*((self as *const Self).cast()) }
718 }
719}
720
721#[cfg(feature = "objc2-core-foundation")]
722impl<ObjectType: ?Sized + Message> AsRef<CFMutableArray<ObjectType>>
723 for NSMutableArray<ObjectType>
724{
725 #[inline]
726 fn as_ref(&self) -> &CFMutableArray<ObjectType> {
727 unsafe { &*((self as *const Self).cast()) }
728 }
729}
730
731impl<ObjectType: ?Sized + Message> NSMutableArray<ObjectType> {
732 #[inline]
738 pub unsafe fn cast_unchecked<NewObjectType: ?Sized + Message>(
739 &self,
740 ) -> &NSMutableArray<NewObjectType> {
741 unsafe { &*((self as *const Self).cast()) }
742 }
743}
744
745#[cfg(feature = "NSObject")]
746extern_conformance!(
747 unsafe impl<ObjectType: ?Sized + NSCoding> NSCoding for NSMutableArray<ObjectType> {}
748);
749
750#[cfg(feature = "NSObject")]
751extern_conformance!(
752 unsafe impl<ObjectType: ?Sized> NSCopying for NSMutableArray<ObjectType> {}
753);
754
755#[cfg(feature = "NSObject")]
756unsafe impl<ObjectType: ?Sized + Message> CopyingHelper for NSMutableArray<ObjectType> {
757 type Result = NSArray<ObjectType>;
758}
759
760#[cfg(feature = "NSEnumerator")]
761extern_conformance!(
762 unsafe impl<ObjectType: ?Sized> NSFastEnumeration for NSMutableArray<ObjectType> {}
763);
764
765#[cfg(feature = "NSObject")]
766extern_conformance!(
767 unsafe impl<ObjectType: ?Sized> NSMutableCopying for NSMutableArray<ObjectType> {}
768);
769
770#[cfg(feature = "NSObject")]
771unsafe impl<ObjectType: ?Sized + Message> MutableCopyingHelper for NSMutableArray<ObjectType> {
772 type Result = Self;
773}
774
775extern_conformance!(
776 unsafe impl<ObjectType: ?Sized> NSObjectProtocol for NSMutableArray<ObjectType> {}
777);
778
779#[cfg(feature = "NSObject")]
780extern_conformance!(
781 unsafe impl<ObjectType: ?Sized + NSSecureCoding> NSSecureCoding for NSMutableArray<ObjectType> {}
782);
783
784impl<ObjectType: Message> NSMutableArray<ObjectType> {
785 extern_methods!(
786 #[unsafe(method(addObject:))]
787 #[unsafe(method_family = none)]
788 pub fn addObject(&self, an_object: &ObjectType);
789
790 #[unsafe(method(insertObject:atIndex:))]
791 #[unsafe(method_family = none)]
792 pub fn insertObject_atIndex(&self, an_object: &ObjectType, index: NSUInteger);
793
794 #[unsafe(method(removeLastObject))]
795 #[unsafe(method_family = none)]
796 pub fn removeLastObject(&self);
797
798 #[unsafe(method(removeObjectAtIndex:))]
799 #[unsafe(method_family = none)]
800 pub fn removeObjectAtIndex(&self, index: NSUInteger);
801
802 #[unsafe(method(replaceObjectAtIndex:withObject:))]
803 #[unsafe(method_family = none)]
804 pub fn replaceObjectAtIndex_withObject(&self, index: NSUInteger, an_object: &ObjectType);
805
806 #[unsafe(method(init))]
807 #[unsafe(method_family = init)]
808 pub fn init(this: Allocated<Self>) -> Retained<Self>;
809
810 #[unsafe(method(initWithCapacity:))]
811 #[unsafe(method_family = init)]
812 pub fn initWithCapacity(this: Allocated<Self>, num_items: NSUInteger) -> Retained<Self>;
813
814 #[cfg(feature = "NSCoder")]
815 #[unsafe(method(initWithCoder:))]
819 #[unsafe(method_family = init)]
820 pub unsafe fn initWithCoder(
821 this: Allocated<Self>,
822 coder: &NSCoder,
823 ) -> Option<Retained<Self>>;
824 );
825}
826
827impl<ObjectType: Message> NSMutableArray<ObjectType> {
829 extern_methods!(
830 #[unsafe(method(initWithObjects:count:))]
834 #[unsafe(method_family = init)]
835 pub unsafe fn initWithObjects_count(
836 this: Allocated<Self>,
837 objects: *mut NonNull<ObjectType>,
838 cnt: NSUInteger,
839 ) -> Retained<Self>;
840 );
841}
842
843impl<ObjectType: Message> NSMutableArray<ObjectType> {
845 extern_methods!(
846 #[unsafe(method(new))]
847 #[unsafe(method_family = new)]
848 pub fn new() -> Retained<Self>;
849 );
850}
851
852impl<ObjectType: Message> DefaultRetained for NSMutableArray<ObjectType> {
853 #[inline]
854 fn default_retained() -> Retained<Self> {
855 Self::new()
856 }
857}
858
859impl<ObjectType: Message> NSMutableArray<ObjectType> {
861 extern_methods!(
862 #[unsafe(method(addObjectsFromArray:))]
863 #[unsafe(method_family = none)]
864 pub fn addObjectsFromArray(&self, other_array: &NSArray<ObjectType>);
865
866 #[unsafe(method(exchangeObjectAtIndex:withObjectAtIndex:))]
867 #[unsafe(method_family = none)]
868 pub fn exchangeObjectAtIndex_withObjectAtIndex(&self, idx1: NSUInteger, idx2: NSUInteger);
869
870 #[unsafe(method(removeAllObjects))]
871 #[unsafe(method_family = none)]
872 pub fn removeAllObjects(&self);
873
874 #[cfg(feature = "NSRange")]
875 #[unsafe(method(removeObject:inRange:))]
876 #[unsafe(method_family = none)]
877 pub fn removeObject_inRange(&self, an_object: &ObjectType, range: NSRange);
878
879 #[unsafe(method(removeObject:))]
880 #[unsafe(method_family = none)]
881 pub fn removeObject(&self, an_object: &ObjectType);
882
883 #[cfg(feature = "NSRange")]
884 #[unsafe(method(removeObjectIdenticalTo:inRange:))]
885 #[unsafe(method_family = none)]
886 pub fn removeObjectIdenticalTo_inRange(&self, an_object: &ObjectType, range: NSRange);
887
888 #[unsafe(method(removeObjectIdenticalTo:))]
889 #[unsafe(method_family = none)]
890 pub fn removeObjectIdenticalTo(&self, an_object: &ObjectType);
891
892 #[deprecated = "Not supported"]
896 #[unsafe(method(removeObjectsFromIndices:numIndices:))]
897 #[unsafe(method_family = none)]
898 pub unsafe fn removeObjectsFromIndices_numIndices(
899 &self,
900 indices: NonNull<NSUInteger>,
901 cnt: NSUInteger,
902 );
903
904 #[unsafe(method(removeObjectsInArray:))]
905 #[unsafe(method_family = none)]
906 pub fn removeObjectsInArray(&self, other_array: &NSArray<ObjectType>);
907
908 #[cfg(feature = "NSRange")]
909 #[unsafe(method(removeObjectsInRange:))]
910 #[unsafe(method_family = none)]
911 pub fn removeObjectsInRange(&self, range: NSRange);
912
913 #[cfg(feature = "NSRange")]
914 #[unsafe(method(replaceObjectsInRange:withObjectsFromArray:range:))]
915 #[unsafe(method_family = none)]
916 pub fn replaceObjectsInRange_withObjectsFromArray_range(
917 &self,
918 range: NSRange,
919 other_array: &NSArray<ObjectType>,
920 other_range: NSRange,
921 );
922
923 #[cfg(feature = "NSRange")]
924 #[unsafe(method(replaceObjectsInRange:withObjectsFromArray:))]
925 #[unsafe(method_family = none)]
926 pub fn replaceObjectsInRange_withObjectsFromArray(
927 &self,
928 range: NSRange,
929 other_array: &NSArray<ObjectType>,
930 );
931
932 #[unsafe(method(setArray:))]
933 #[unsafe(method_family = none)]
934 pub fn setArray(&self, other_array: &NSArray<ObjectType>);
935
936 #[unsafe(method(sortUsingFunction:context:))]
941 #[unsafe(method_family = none)]
942 pub unsafe fn sortUsingFunction_context(
943 &self,
944 compare: unsafe extern "C-unwind" fn(
945 NonNull<ObjectType>,
946 NonNull<ObjectType>,
947 *mut c_void,
948 ) -> NSInteger,
949 context: *mut c_void,
950 );
951
952 #[unsafe(method(sortUsingSelector:))]
956 #[unsafe(method_family = none)]
957 pub unsafe fn sortUsingSelector(&self, comparator: Sel);
958
959 #[cfg(feature = "NSIndexSet")]
960 #[unsafe(method(insertObjects:atIndexes:))]
961 #[unsafe(method_family = none)]
962 pub fn insertObjects_atIndexes(&self, objects: &NSArray<ObjectType>, indexes: &NSIndexSet);
963
964 #[cfg(feature = "NSIndexSet")]
965 #[unsafe(method(removeObjectsAtIndexes:))]
966 #[unsafe(method_family = none)]
967 pub fn removeObjectsAtIndexes(&self, indexes: &NSIndexSet);
968
969 #[cfg(feature = "NSIndexSet")]
970 #[unsafe(method(replaceObjectsAtIndexes:withObjects:))]
971 #[unsafe(method_family = none)]
972 pub fn replaceObjectsAtIndexes_withObjects(
973 &self,
974 indexes: &NSIndexSet,
975 objects: &NSArray<ObjectType>,
976 );
977
978 #[unsafe(method(setObject:atIndexedSubscript:))]
979 #[unsafe(method_family = none)]
980 pub fn setObject_atIndexedSubscript(&self, obj: &ObjectType, idx: NSUInteger);
981
982 #[cfg(all(feature = "NSObjCRuntime", feature = "block2"))]
983 #[unsafe(method(sortUsingComparator:))]
987 #[unsafe(method_family = none)]
988 pub unsafe fn sortUsingComparator(&self, cmptr: NSComparator);
989
990 #[cfg(all(feature = "NSObjCRuntime", feature = "block2"))]
991 #[unsafe(method(sortWithOptions:usingComparator:))]
995 #[unsafe(method_family = none)]
996 pub unsafe fn sortWithOptions_usingComparator(
997 &self,
998 opts: NSSortOptions,
999 cmptr: NSComparator,
1000 );
1001 );
1002}
1003
1004impl<ObjectType: Message> NSMutableArray<ObjectType> {
1006 extern_methods!(
1007 #[unsafe(method(arrayWithCapacity:))]
1008 #[unsafe(method_family = none)]
1009 pub fn arrayWithCapacity(num_items: NSUInteger) -> Retained<Self>;
1010
1011 #[cfg(feature = "NSString")]
1012 #[unsafe(method(arrayWithContentsOfFile:))]
1013 #[unsafe(method_family = none)]
1014 pub unsafe fn arrayWithContentsOfFile(
1015 path: &NSString,
1016 ) -> Option<Retained<NSMutableArray<ObjectType>>>;
1017
1018 #[cfg(feature = "NSURL")]
1019 #[unsafe(method(arrayWithContentsOfURL:))]
1020 #[unsafe(method_family = none)]
1021 pub unsafe fn arrayWithContentsOfURL(
1022 url: &NSURL,
1023 ) -> Option<Retained<NSMutableArray<ObjectType>>>;
1024
1025 #[cfg(feature = "NSString")]
1026 #[unsafe(method(initWithContentsOfFile:))]
1027 #[unsafe(method_family = init)]
1028 pub unsafe fn initWithContentsOfFile(
1029 this: Allocated<Self>,
1030 path: &NSString,
1031 ) -> Option<Retained<NSMutableArray<ObjectType>>>;
1032
1033 #[cfg(feature = "NSURL")]
1034 #[unsafe(method(initWithContentsOfURL:))]
1035 #[unsafe(method_family = init)]
1036 pub unsafe fn initWithContentsOfURL(
1037 this: Allocated<Self>,
1038 url: &NSURL,
1039 ) -> Option<Retained<NSMutableArray<ObjectType>>>;
1040 );
1041}
1042
1043impl<ObjectType: Message> NSMutableArray<ObjectType> {
1045 extern_methods!(
1046 #[cfg(feature = "NSOrderedCollectionDifference")]
1047 #[unsafe(method(applyDifference:))]
1048 #[unsafe(method_family = none)]
1049 pub fn applyDifference(&self, difference: &NSOrderedCollectionDifference<ObjectType>);
1050 );
1051}