#[repr(C)]pub struct NSMutableArray<ObjectType: ?Sized = AnyObject> { /* private fields */ }
NSArray
only.Expand description
************** Mutable Array ***************
See also Apple’s documentation
Implementations§
Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
Convenience creation methods.
impl<ObjectType: Message> NSMutableArray<ObjectType>
Convenience creation methods.
pub fn from_slice(slice: &[&ObjectType]) -> Retained<Self>
pub fn from_retained_slice(slice: &[Retained<ObjectType>]) -> Retained<Self>
Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
Convenience mutation methods.
impl<ObjectType: Message> NSMutableArray<ObjectType>
Convenience mutation methods.
Sourcepub fn insert(&self, index: usize, obj: &ObjectType)
pub fn insert(&self, index: usize, obj: &ObjectType)
Sourcepub fn sort_by<F: FnMut(&ObjectType, &ObjectType) -> Ordering>(
&self,
compare: F,
)
Available on crate feature NSObjCRuntime
only.
pub fn sort_by<F: FnMut(&ObjectType, &ObjectType) -> Ordering>( &self, compare: F, )
NSObjCRuntime
only.Sort the array by the given comparison closure.
Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
Methods declared on superclass NSArray
.
impl<ObjectType: Message> NSMutableArray<ObjectType>
Methods declared on superclass NSArray
.
NSArrayCreation.
pub unsafe fn array() -> Retained<Self>
pub unsafe fn arrayWithObject(an_object: &ObjectType) -> Retained<Self>
pub unsafe fn arrayWithObjects_count( objects: NonNull<NonNull<ObjectType>>, cnt: NSUInteger, ) -> Retained<Self>
pub unsafe fn arrayWithArray(array: &NSArray<ObjectType>) -> Retained<Self>
pub unsafe fn initWithArray( this: Allocated<Self>, array: &NSArray<ObjectType>, ) -> Retained<Self>
pub unsafe fn initWithArray_copyItems( this: Allocated<Self>, array: &NSArray<ObjectType>, flag: bool, ) -> Retained<Self>
Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
impl<ObjectType: Message> NSMutableArray<ObjectType>
pub fn addObject(&self, an_object: &ObjectType)
pub fn insertObject_atIndex(&self, an_object: &ObjectType, index: NSUInteger)
pub fn removeLastObject(&self)
pub fn removeObjectAtIndex(&self, index: NSUInteger)
pub fn replaceObjectAtIndex_withObject( &self, index: NSUInteger, an_object: &ObjectType, )
pub fn init(this: Allocated<Self>) -> Retained<Self>
pub fn initWithCapacity( this: Allocated<Self>, num_items: NSUInteger, ) -> Retained<Self>
pub unsafe fn initWithCoder( this: Allocated<Self>, coder: &NSCoder, ) -> Option<Retained<Self>>
NSCoder
only.Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
Methods declared on superclass NSArray
.
impl<ObjectType: Message> NSMutableArray<ObjectType>
Methods declared on superclass NSArray
.
pub unsafe fn initWithObjects_count( this: Allocated<Self>, objects: *mut NonNull<ObjectType>, cnt: NSUInteger, ) -> Retained<Self>
Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
Methods declared on superclass NSObject
.
impl<ObjectType: Message> NSMutableArray<ObjectType>
Methods declared on superclass NSObject
.
Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
NSExtendedMutableArray.
impl<ObjectType: Message> NSMutableArray<ObjectType>
NSExtendedMutableArray.
pub unsafe fn addObjectsFromArray(&self, other_array: &NSArray<ObjectType>)
pub unsafe fn exchangeObjectAtIndex_withObjectAtIndex( &self, idx1: NSUInteger, idx2: NSUInteger, )
pub fn removeAllObjects(&self)
pub unsafe fn removeObject_inRange( &self, an_object: &ObjectType, range: NSRange, )
NSRange
only.pub fn removeObject(&self, an_object: &ObjectType)
pub unsafe fn removeObjectIdenticalTo_inRange( &self, an_object: &ObjectType, range: NSRange, )
NSRange
only.pub unsafe fn removeObjectIdenticalTo(&self, an_object: &ObjectType)
pub unsafe fn removeObjectsFromIndices_numIndices( &self, indices: NonNull<NSUInteger>, cnt: NSUInteger, )
pub unsafe fn removeObjectsInArray(&self, other_array: &NSArray<ObjectType>)
pub unsafe fn removeObjectsInRange(&self, range: NSRange)
NSRange
only.pub unsafe fn replaceObjectsInRange_withObjectsFromArray_range( &self, range: NSRange, other_array: &NSArray<ObjectType>, other_range: NSRange, )
NSRange
only.pub unsafe fn replaceObjectsInRange_withObjectsFromArray( &self, range: NSRange, other_array: &NSArray<ObjectType>, )
NSRange
only.pub unsafe fn setArray(&self, other_array: &NSArray<ObjectType>)
pub unsafe fn sortUsingFunction_context( &self, compare: unsafe extern "C-unwind" fn(NonNull<ObjectType>, NonNull<ObjectType>, *mut c_void) -> NSInteger, context: *mut c_void, )
pub unsafe fn sortUsingSelector(&self, comparator: Sel)
pub unsafe fn insertObjects_atIndexes( &self, objects: &NSArray<ObjectType>, indexes: &NSIndexSet, )
NSIndexSet
only.pub unsafe fn removeObjectsAtIndexes(&self, indexes: &NSIndexSet)
NSIndexSet
only.pub unsafe fn replaceObjectsAtIndexes_withObjects( &self, indexes: &NSIndexSet, objects: &NSArray<ObjectType>, )
NSIndexSet
only.pub unsafe fn setObject_atIndexedSubscript( &self, obj: &ObjectType, idx: NSUInteger, )
pub unsafe fn sortUsingComparator(&self, cmptr: NSComparator)
NSObjCRuntime
and block2
only.pub unsafe fn sortWithOptions_usingComparator( &self, opts: NSSortOptions, cmptr: NSComparator, )
NSObjCRuntime
and block2
only.Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
NSMutableArrayCreation.
impl<ObjectType: Message> NSMutableArray<ObjectType>
NSMutableArrayCreation.
pub unsafe fn arrayWithCapacity(num_items: NSUInteger) -> Retained<Self>
pub unsafe fn arrayWithContentsOfFile( path: &NSString, ) -> Option<Retained<NSMutableArray<ObjectType>>>
NSString
only.pub unsafe fn arrayWithContentsOfURL( url: &NSURL, ) -> Option<Retained<NSMutableArray<ObjectType>>>
NSURL
only.pub unsafe fn initWithContentsOfFile( this: Allocated<Self>, path: &NSString, ) -> Option<Retained<NSMutableArray<ObjectType>>>
NSString
only.pub unsafe fn initWithContentsOfURL( this: Allocated<Self>, url: &NSURL, ) -> Option<Retained<NSMutableArray<ObjectType>>>
NSURL
only.Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
NSMutableArrayDiffing.
impl<ObjectType: Message> NSMutableArray<ObjectType>
NSMutableArrayDiffing.
pub unsafe fn applyDifference( &self, difference: &NSOrderedCollectionDifference<ObjectType>, )
NSOrderedCollectionDifference
only.Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
NSPredicateSupport.
impl<ObjectType: Message> NSMutableArray<ObjectType>
NSPredicateSupport.
pub unsafe fn filterUsingPredicate(&self, predicate: &NSPredicate)
NSPredicate
only.Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
NSSortDescriptorSorting.
impl<ObjectType: Message> NSMutableArray<ObjectType>
NSSortDescriptorSorting.
pub unsafe fn sortUsingDescriptors( &self, sort_descriptors: &NSArray<NSSortDescriptor>, )
NSSortDescriptor
only.Methods from Deref<Target = NSArray<ObjectType>>§
Sourcepub unsafe fn objectAtIndex_unchecked(&self, index: usize) -> &ObjectType
pub unsafe fn objectAtIndex_unchecked(&self, index: usize) -> &ObjectType
Get a direct reference to one of the array’s objects.
Throws an error if the object was not found.
Consider using the objectAtIndex
method
instead, unless you’re seeing performance issues from the retaining.
§Safety
The array must not be mutated while the reference is live.
Sourcepub unsafe fn firstObject_unchecked(&self) -> Option<&ObjectType>
pub unsafe fn firstObject_unchecked(&self) -> Option<&ObjectType>
A direct reference to the array’s first object, if any.
Consider using the firstObject
method instead,
unless you’re seeing performance issues from the retaining.
§Safety
The array must not be mutated while the reference is live.
Sourcepub unsafe fn lastObject_unchecked(&self) -> Option<&ObjectType>
pub unsafe fn lastObject_unchecked(&self) -> Option<&ObjectType>
A direct reference to the array’s last object, if any.
Consider using the lastObject
method instead,
unless you’re seeing performance issues from the retaining.
§Safety
The array must not be mutated while the reference is live.
Sourcepub unsafe fn to_vec_unchecked(&self) -> Vec<&ObjectType>
pub unsafe fn to_vec_unchecked(&self) -> Vec<&ObjectType>
Sourcepub unsafe fn iter_unchecked(&self) -> IterUnchecked<'_, ObjectType> ⓘ
Available on crate feature NSEnumerator
only.
pub unsafe fn iter_unchecked(&self) -> IterUnchecked<'_, ObjectType> ⓘ
NSEnumerator
only.Sourcepub fn to_vec(&self) -> Vec<Retained<ObjectType>>
pub fn to_vec(&self) -> Vec<Retained<ObjectType>>
Convert the array to a Vec
of the array’s objects.
Sourcepub fn iter(&self) -> Iter<'_, ObjectType> ⓘ
Available on crate feature NSEnumerator
only.
pub fn iter(&self) -> Iter<'_, ObjectType> ⓘ
NSEnumerator
only.Iterate over the array’s elements.
Sourcepub fn objects_in_range(&self, range: Range<usize>) -> Vec<Retained<ObjectType>>
Available on crate feature NSRange
only.
pub fn objects_in_range(&self, range: Range<usize>) -> Vec<Retained<ObjectType>>
NSRange
only.pub fn count(&self) -> NSUInteger
pub fn objectAtIndex(&self, index: NSUInteger) -> Retained<ObjectType>
pub unsafe fn arrayByAddingObject( &self, an_object: &ObjectType, ) -> Retained<NSArray<ObjectType>>
pub unsafe fn arrayByAddingObjectsFromArray( &self, other_array: &NSArray<ObjectType>, ) -> Retained<NSArray<ObjectType>>
pub unsafe fn componentsJoinedByString( &self, separator: &NSString, ) -> Retained<NSString>
NSString
only.pub unsafe fn containsObject(&self, an_object: &ObjectType) -> bool
pub unsafe fn description(&self) -> Retained<NSString>
NSString
only.pub unsafe fn descriptionWithLocale( &self, locale: Option<&AnyObject>, ) -> Retained<NSString>
NSString
only.pub unsafe fn descriptionWithLocale_indent( &self, locale: Option<&AnyObject>, level: NSUInteger, ) -> Retained<NSString>
NSString
only.pub unsafe fn firstObjectCommonWithArray( &self, other_array: &NSArray<ObjectType>, ) -> Option<Retained<ObjectType>>
pub unsafe fn getObjects_range( &self, objects: NonNull<NonNull<ObjectType>>, range: NSRange, )
NSRange
only.pub unsafe fn indexOfObject(&self, an_object: &ObjectType) -> NSUInteger
pub unsafe fn indexOfObject_inRange( &self, an_object: &ObjectType, range: NSRange, ) -> NSUInteger
NSRange
only.pub unsafe fn indexOfObjectIdenticalTo( &self, an_object: &ObjectType, ) -> NSUInteger
pub unsafe fn indexOfObjectIdenticalTo_inRange( &self, an_object: &ObjectType, range: NSRange, ) -> NSUInteger
NSRange
only.pub unsafe fn isEqualToArray(&self, other_array: &NSArray<ObjectType>) -> bool
pub fn firstObject(&self) -> Option<Retained<ObjectType>>
pub fn lastObject(&self) -> Option<Retained<ObjectType>>
pub unsafe fn objectEnumerator(&self) -> Retained<NSEnumerator<ObjectType>>
NSEnumerator
only.pub unsafe fn reverseObjectEnumerator( &self, ) -> Retained<NSEnumerator<ObjectType>>
NSEnumerator
only.pub unsafe fn sortedArrayHint(&self) -> Retained<NSData>
NSData
only.pub unsafe fn sortedArrayUsingFunction_context( &self, comparator: unsafe extern "C-unwind" fn(NonNull<ObjectType>, NonNull<ObjectType>, *mut c_void) -> NSInteger, context: *mut c_void, ) -> Retained<NSArray<ObjectType>>
pub unsafe fn sortedArrayUsingFunction_context_hint( &self, comparator: unsafe extern "C-unwind" fn(NonNull<ObjectType>, NonNull<ObjectType>, *mut c_void) -> NSInteger, context: *mut c_void, hint: Option<&NSData>, ) -> Retained<NSArray<ObjectType>>
NSData
only.pub unsafe fn sortedArrayUsingSelector( &self, comparator: Sel, ) -> Retained<NSArray<ObjectType>>
pub unsafe fn subarrayWithRange( &self, range: NSRange, ) -> Retained<NSArray<ObjectType>>
NSRange
only.pub unsafe fn writeToURL_error( &self, url: &NSURL, ) -> Result<(), Retained<NSError>>
NSError
and NSURL
only.pub unsafe fn makeObjectsPerformSelector(&self, a_selector: Sel)
pub unsafe fn makeObjectsPerformSelector_withObject( &self, a_selector: Sel, argument: Option<&AnyObject>, )
pub unsafe fn objectsAtIndexes( &self, indexes: &NSIndexSet, ) -> Retained<NSArray<ObjectType>>
NSIndexSet
only.pub unsafe fn objectAtIndexedSubscript( &self, idx: NSUInteger, ) -> Retained<ObjectType>
pub unsafe fn enumerateObjectsUsingBlock( &self, block: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) + '_>, )
block2
only.pub unsafe fn enumerateObjectsWithOptions_usingBlock( &self, opts: NSEnumerationOptions, block: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) + '_>, )
NSObjCRuntime
and block2
only.pub unsafe fn enumerateObjectsAtIndexes_options_usingBlock( &self, s: &NSIndexSet, opts: NSEnumerationOptions, block: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) + '_>, )
NSIndexSet
and NSObjCRuntime
and block2
only.pub unsafe fn indexOfObjectPassingTest( &self, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_>, ) -> NSUInteger
block2
only.pub unsafe fn indexOfObjectWithOptions_passingTest( &self, opts: NSEnumerationOptions, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_>, ) -> NSUInteger
NSObjCRuntime
and block2
only.pub unsafe fn indexOfObjectAtIndexes_options_passingTest( &self, s: &NSIndexSet, opts: NSEnumerationOptions, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_>, ) -> NSUInteger
NSIndexSet
and NSObjCRuntime
and block2
only.pub unsafe fn indexesOfObjectsPassingTest( &self, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_>, ) -> Retained<NSIndexSet>
NSIndexSet
and block2
only.pub unsafe fn indexesOfObjectsWithOptions_passingTest( &self, opts: NSEnumerationOptions, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_>, ) -> Retained<NSIndexSet>
NSIndexSet
and NSObjCRuntime
and block2
only.pub unsafe fn indexesOfObjectsAtIndexes_options_passingTest( &self, s: &NSIndexSet, opts: NSEnumerationOptions, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_>, ) -> Retained<NSIndexSet>
NSIndexSet
and NSObjCRuntime
and block2
only.pub unsafe fn sortedArrayUsingComparator( &self, cmptr: NSComparator, ) -> Retained<NSArray<ObjectType>>
NSObjCRuntime
and block2
only.pub unsafe fn sortedArrayWithOptions_usingComparator( &self, opts: NSSortOptions, cmptr: NSComparator, ) -> Retained<NSArray<ObjectType>>
NSObjCRuntime
and block2
only.pub unsafe fn indexOfObject_inSortedRange_options_usingComparator( &self, obj: &ObjectType, r: NSRange, opts: NSBinarySearchingOptions, cmp: NSComparator, ) -> NSUInteger
NSObjCRuntime
and NSRange
and block2
only.pub unsafe fn differenceFromArray_withOptions_usingEquivalenceTest( &self, other: &NSArray<ObjectType>, options: NSOrderedCollectionDifferenceCalculationOptions, block: &DynBlock<dyn Fn(NonNull<ObjectType>, NonNull<ObjectType>) -> Bool + '_>, ) -> Retained<NSOrderedCollectionDifference<ObjectType>>
NSOrderedCollectionDifference
and block2
only.pub unsafe fn differenceFromArray_withOptions( &self, other: &NSArray<ObjectType>, options: NSOrderedCollectionDifferenceCalculationOptions, ) -> Retained<NSOrderedCollectionDifference<ObjectType>>
NSOrderedCollectionDifference
only.pub unsafe fn differenceFromArray( &self, other: &NSArray<ObjectType>, ) -> Retained<NSOrderedCollectionDifference<ObjectType>>
NSOrderedCollectionDifference
only.pub unsafe fn arrayByApplyingDifference( &self, difference: &NSOrderedCollectionDifference<ObjectType>, ) -> Option<Retained<NSArray<ObjectType>>>
NSOrderedCollectionDifference
only.pub unsafe fn getObjects(&self, objects: NonNull<NonNull<ObjectType>>)
pub unsafe fn writeToFile_atomically( &self, path: &NSString, use_auxiliary_file: bool, ) -> bool
NSString
only.pub unsafe fn writeToURL_atomically( &self, url: &NSURL, atomically: bool, ) -> bool
NSURL
only.pub unsafe fn valueForKey(&self, key: &NSString) -> Retained<AnyObject>
NSKeyValueCoding
and NSString
only.pub unsafe fn setValue_forKey(&self, value: Option<&AnyObject>, key: &NSString)
NSKeyValueCoding
and NSString
only.pub unsafe fn addObserver_toObjectsAtIndexes_forKeyPath_options_context( &self, observer: &NSObject, indexes: &NSIndexSet, key_path: &NSString, options: NSKeyValueObservingOptions, context: *mut c_void, )
NSKeyValueObserving
and NSIndexSet
and NSString
only.pub unsafe fn removeObserver_fromObjectsAtIndexes_forKeyPath_context( &self, observer: &NSObject, indexes: &NSIndexSet, key_path: &NSString, context: *mut c_void, )
NSKeyValueObserving
and NSIndexSet
and NSString
only.pub unsafe fn removeObserver_fromObjectsAtIndexes_forKeyPath( &self, observer: &NSObject, indexes: &NSIndexSet, key_path: &NSString, )
NSKeyValueObserving
and NSIndexSet
and NSString
only.pub unsafe fn addObserver_forKeyPath_options_context( &self, observer: &NSObject, key_path: &NSString, options: NSKeyValueObservingOptions, context: *mut c_void, )
NSKeyValueObserving
and NSString
only.pub unsafe fn removeObserver_forKeyPath_context( &self, observer: &NSObject, key_path: &NSString, context: *mut c_void, )
NSKeyValueObserving
and NSString
only.pub unsafe fn removeObserver_forKeyPath( &self, observer: &NSObject, key_path: &NSString, )
NSKeyValueObserving
and NSString
only.pub unsafe fn pathsMatchingExtensions( &self, filter_types: &NSArray<NSString>, ) -> Retained<NSArray<NSString>>
NSPathUtilities
and NSString
only.pub unsafe fn filteredArrayUsingPredicate( &self, predicate: &NSPredicate, ) -> Retained<NSArray<ObjectType>>
NSPredicate
only.pub unsafe fn sortedArrayUsingDescriptors( &self, sort_descriptors: &NSArray<NSSortDescriptor>, ) -> Retained<NSArray<ObjectType>>
NSSortDescriptor
only.Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init
/new
methods).
§Example
Check that an instance of NSObject
has the precise class NSObject
.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load
instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load
instead.Use Ivar::load
instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T
.
See Ivar::load_ptr
for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T
.
This is the reference-variant. Use Retained::downcast
if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString
.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString
to a NSMutableString
,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass:
for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject
.
§Panics
This works internally by calling isKindOfClass:
. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject
and
NSProxy
implement this method.
§Examples
Cast an NSString
back and forth from NSObject
.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();
Try (and fail) to cast an NSObject
to an NSString
.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());
Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();
This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}
Trait Implementations§
Source§impl<ObjectType: ?Sized + Message> AsRef<NSMutableArray<ObjectType>> for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized + Message> AsRef<NSMutableArray<ObjectType>> for NSMutableArray<ObjectType>
Source§impl<ObjectType: ?Sized + Message> Borrow<NSArray<ObjectType>> for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized + Message> Borrow<NSArray<ObjectType>> for NSMutableArray<ObjectType>
Source§impl<ObjectType: ?Sized + Message> ClassType for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized + Message> ClassType for NSMutableArray<ObjectType>
Source§const NAME: &'static str = "NSMutableArray"
const NAME: &'static str = "NSMutableArray"
Source§type ThreadKind = <<NSMutableArray<ObjectType> as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSMutableArray<ObjectType> as ClassType>::Super as ClassType>::ThreadKind
Source§impl<ObjectType: ?Sized + Message> CopyingHelper for NSMutableArray<ObjectType>
Available on crate feature NSObject
only.
impl<ObjectType: ?Sized + Message> CopyingHelper for NSMutableArray<ObjectType>
NSObject
only.Source§impl<ObjectType: Debug + Message> Debug for NSMutableArray<ObjectType>
Available on crate feature NSEnumerator
only.
impl<ObjectType: Debug + Message> Debug for NSMutableArray<ObjectType>
NSEnumerator
only.Source§impl<ObjectType: Message> DefaultRetained for NSMutableArray<ObjectType>
impl<ObjectType: Message> DefaultRetained for NSMutableArray<ObjectType>
Source§impl<'a, ObjectType: Message> Extend<&'a ObjectType> for &NSMutableArray<ObjectType>
impl<'a, ObjectType: Message> Extend<&'a ObjectType> for &NSMutableArray<ObjectType>
Source§fn extend<I: IntoIterator<Item = &'a ObjectType>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a ObjectType>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<ObjectType: Message> Extend<Retained<ObjectType>> for &NSMutableArray<ObjectType>
impl<ObjectType: Message> Extend<Retained<ObjectType>> for &NSMutableArray<ObjectType>
Source§fn extend<I: IntoIterator<Item = Retained<ObjectType>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Retained<ObjectType>>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<ObjectType: ?Sized> Hash for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized> Hash for NSMutableArray<ObjectType>
Source§impl<'a, ObjectType: Message> IntoIterator for &'a NSMutableArray<ObjectType>
impl<'a, ObjectType: Message> IntoIterator for &'a NSMutableArray<ObjectType>
Source§impl<ObjectType: ?Sized + Message> MutableCopyingHelper for NSMutableArray<ObjectType>
Available on crate feature NSObject
only.
impl<ObjectType: ?Sized + Message> MutableCopyingHelper for NSMutableArray<ObjectType>
NSObject
only.Source§type Result = NSMutableArray<ObjectType>
type Result = NSMutableArray<ObjectType>
Self
if the type has no
mutable counterpart. Read moreSource§impl<ObjectType: ?Sized + NSCoding> NSCoding for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized + NSCoding> NSCoding for NSMutableArray<ObjectType>
Source§unsafe fn encodeWithCoder(&self, coder: &NSCoder)
unsafe fn encodeWithCoder(&self, coder: &NSCoder)
NSObject
and NSCoder
only.Source§impl<ObjectType: ?Sized> NSCopying for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized> NSCopying for NSMutableArray<ObjectType>
Source§impl<ObjectType: ?Sized> NSFastEnumeration for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized> NSFastEnumeration for NSMutableArray<ObjectType>
Source§unsafe fn countByEnumeratingWithState_objects_count(
&self,
state: NonNull<NSFastEnumerationState>,
buffer: NonNull<*mut AnyObject>,
len: NSUInteger,
) -> NSUInteger
unsafe fn countByEnumeratingWithState_objects_count( &self, state: NonNull<NSFastEnumerationState>, buffer: NonNull<*mut AnyObject>, len: NSUInteger, ) -> NSUInteger
NSEnumerator
only.Source§impl<ObjectType: ?Sized> NSMutableCopying for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized> NSMutableCopying for NSMutableArray<ObjectType>
Source§impl<ObjectType: ?Sized> NSObjectProtocol for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized> NSObjectProtocol for NSMutableArray<ObjectType>
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass
directly, or cast your objects with AnyObject::downcast_ref
Source§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
Source§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
Source§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
Source§fn debugDescription(&self) -> Retained<NSObject>
fn debugDescription(&self) -> Retained<NSObject>
Source§impl<ObjectType: ?Sized + NSSecureCoding> NSSecureCoding for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized + NSSecureCoding> NSSecureCoding for NSMutableArray<ObjectType>
Source§impl<ObjectType: ?Sized> PartialEq for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized> PartialEq for NSMutableArray<ObjectType>
Source§impl<ObjectType: ?Sized + Message> RefEncode for NSMutableArray<ObjectType>
impl<ObjectType: ?Sized + Message> RefEncode for NSMutableArray<ObjectType>
Source§const ENCODING_REF: Encoding = <NSArray<ObjectType> as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <NSArray<ObjectType> as ::objc2::RefEncode>::ENCODING_REF
Source§impl<'a, ObjectType: Message + 'a> RetainedFromIterator<&'a ObjectType> for NSMutableArray<ObjectType>
impl<'a, ObjectType: Message + 'a> RetainedFromIterator<&'a ObjectType> for NSMutableArray<ObjectType>
Source§fn retained_from_iter<I: IntoIterator<Item = &'a ObjectType>>(
iter: I,
) -> Retained<Self>
fn retained_from_iter<I: IntoIterator<Item = &'a ObjectType>>( iter: I, ) -> Retained<Self>
Retained
from an iterator.Source§impl<ObjectType: Message> RetainedFromIterator<Retained<ObjectType>> for NSMutableArray<ObjectType>
impl<ObjectType: Message> RetainedFromIterator<Retained<ObjectType>> for NSMutableArray<ObjectType>
Source§fn retained_from_iter<I: IntoIterator<Item = Retained<ObjectType>>>(
iter: I,
) -> Retained<Self>
fn retained_from_iter<I: IntoIterator<Item = Retained<ObjectType>>>( iter: I, ) -> Retained<Self>
Retained
from an iterator.Source§impl<ObjectType: Message> RetainedIntoIterator for NSMutableArray<ObjectType>
impl<ObjectType: Message> RetainedIntoIterator for NSMutableArray<ObjectType>
Source§impl<ObjectType: Message> ToOwned for NSMutableArray<ObjectType>
Available on crate feature NSObject
only.
impl<ObjectType: Message> ToOwned for NSMutableArray<ObjectType>
NSObject
only.