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 fn array() -> Retained<Self>
pub fn arrayWithObject(an_object: &ObjectType) -> Retained<Self>
Sourcepub unsafe fn arrayWithObjects_count(
objects: NonNull<NonNull<ObjectType>>,
cnt: NSUInteger,
) -> Retained<Self>
pub unsafe fn arrayWithObjects_count( objects: NonNull<NonNull<ObjectType>>, cnt: NSUInteger, ) -> Retained<Self>
§Safety
objects must be a valid pointer.
pub fn arrayWithArray(array: &NSArray<ObjectType>) -> Retained<Self>
pub 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: ?Sized + Message> NSMutableArray<ObjectType>
impl<ObjectType: ?Sized + Message> NSMutableArray<ObjectType>
Sourcepub unsafe fn cast_unchecked<NewObjectType: ?Sized + Message>(
&self,
) -> &NSMutableArray<NewObjectType>
pub unsafe fn cast_unchecked<NewObjectType: ?Sized + Message>( &self, ) -> &NSMutableArray<NewObjectType>
Unchecked conversion of the generic parameter.
§Safety
The generic must be valid to reinterpret as the given type.
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>
Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
Methods declared on superclass NSArray.
impl<ObjectType: Message> NSMutableArray<ObjectType>
Methods declared on superclass NSArray.
Sourcepub unsafe fn initWithObjects_count(
this: Allocated<Self>,
objects: *mut NonNull<ObjectType>,
cnt: NSUInteger,
) -> Retained<Self>
pub unsafe fn initWithObjects_count( this: Allocated<Self>, objects: *mut NonNull<ObjectType>, cnt: NSUInteger, ) -> Retained<Self>
§Safety
objects must be a valid pointer or null.
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 fn addObjectsFromArray(&self, other_array: &NSArray<ObjectType>)
pub fn exchangeObjectAtIndex_withObjectAtIndex( &self, idx1: NSUInteger, idx2: NSUInteger, )
pub fn removeAllObjects(&self)
pub fn removeObject_inRange(&self, an_object: &ObjectType, range: NSRange)
NSRange only.pub fn removeObject(&self, an_object: &ObjectType)
pub fn removeObjectIdenticalTo_inRange( &self, an_object: &ObjectType, range: NSRange, )
NSRange only.pub fn removeObjectIdenticalTo(&self, an_object: &ObjectType)
Sourcepub unsafe fn removeObjectsFromIndices_numIndices(
&self,
indices: NonNull<NSUInteger>,
cnt: NSUInteger,
)
👎Deprecated: Not supported
pub unsafe fn removeObjectsFromIndices_numIndices( &self, indices: NonNull<NSUInteger>, cnt: NSUInteger, )
§Safety
indices must be a valid pointer.
pub fn removeObjectsInArray(&self, other_array: &NSArray<ObjectType>)
pub fn removeObjectsInRange(&self, range: NSRange)
NSRange only.pub fn replaceObjectsInRange_withObjectsFromArray_range( &self, range: NSRange, other_array: &NSArray<ObjectType>, other_range: NSRange, )
NSRange only.pub fn replaceObjectsInRange_withObjectsFromArray( &self, range: NSRange, other_array: &NSArray<ObjectType>, )
NSRange only.pub fn setArray(&self, other_array: &NSArray<ObjectType>)
Sourcepub 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 sortUsingFunction_context( &self, compare: unsafe extern "C-unwind" fn(NonNull<ObjectType>, NonNull<ObjectType>, *mut c_void) -> NSInteger, context: *mut c_void, )
§Safety
comparemust be implemented correctly.contextmust be a valid pointer or null.
Sourcepub unsafe fn sortUsingSelector(&self, comparator: Sel)
pub unsafe fn sortUsingSelector(&self, comparator: Sel)
§Safety
comparator must be a valid selector.
pub fn insertObjects_atIndexes( &self, objects: &NSArray<ObjectType>, indexes: &NSIndexSet, )
NSIndexSet only.pub fn removeObjectsAtIndexes(&self, indexes: &NSIndexSet)
NSIndexSet only.pub fn replaceObjectsAtIndexes_withObjects( &self, indexes: &NSIndexSet, objects: &NSArray<ObjectType>, )
NSIndexSet only.pub fn setObject_atIndexedSubscript(&self, obj: &ObjectType, idx: NSUInteger)
Sourcepub unsafe fn sortUsingComparator(&self, cmptr: NSComparator)
Available on crate features NSObjCRuntime and block2 only.
pub unsafe fn sortUsingComparator(&self, cmptr: NSComparator)
NSObjCRuntime and block2 only.§Safety
cmptr must be a valid pointer.
Sourcepub unsafe fn sortWithOptions_usingComparator(
&self,
opts: NSSortOptions,
cmptr: NSComparator,
)
Available on crate features NSObjCRuntime and block2 only.
pub unsafe fn sortWithOptions_usingComparator( &self, opts: NSSortOptions, cmptr: NSComparator, )
NSObjCRuntime and block2 only.§Safety
cmptr must be a valid pointer.
Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
NSMutableArrayCreation.
impl<ObjectType: Message> NSMutableArray<ObjectType>
NSMutableArrayCreation.
pub 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 fn applyDifference( &self, difference: &NSOrderedCollectionDifference<ObjectType>, )
NSOrderedCollectionDifference only.Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
NSPredicateSupport.
impl<ObjectType: Message> NSMutableArray<ObjectType>
NSPredicateSupport.
pub fn filterUsingPredicate(&self, predicate: &NSPredicate)
NSPredicate only.Source§impl<ObjectType: Message> NSMutableArray<ObjectType>
NSSortDescriptorSorting.
impl<ObjectType: Message> NSMutableArray<ObjectType>
NSSortDescriptorSorting.
pub 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.Sourcepub unsafe fn cast_unchecked<NewObjectType: ?Sized + Message>(
&self,
) -> &NSArray<NewObjectType>
pub unsafe fn cast_unchecked<NewObjectType: ?Sized + Message>( &self, ) -> &NSArray<NewObjectType>
Unchecked conversion of the generic parameter.
§Safety
The generic must be valid to reinterpret as the given type.
pub fn count(&self) -> NSUInteger
pub fn objectAtIndex(&self, index: NSUInteger) -> Retained<ObjectType>
pub fn arrayByAddingObject( &self, an_object: &ObjectType, ) -> Retained<NSArray<ObjectType>>
pub fn arrayByAddingObjectsFromArray( &self, other_array: &NSArray<ObjectType>, ) -> Retained<NSArray<ObjectType>>
pub fn componentsJoinedByString( &self, separator: &NSString, ) -> Retained<NSString>
NSString only.pub fn containsObject(&self, an_object: &ObjectType) -> bool
pub fn description(&self) -> Retained<NSString>
NSString only.Sourcepub unsafe fn descriptionWithLocale(
&self,
locale: Option<&AnyObject>,
) -> Retained<NSString>
Available on crate feature NSString only.
pub unsafe fn descriptionWithLocale( &self, locale: Option<&AnyObject>, ) -> Retained<NSString>
NSString only.§Safety
locale should be of the correct type.
Sourcepub unsafe fn descriptionWithLocale_indent(
&self,
locale: Option<&AnyObject>,
level: NSUInteger,
) -> Retained<NSString>
Available on crate feature NSString only.
pub unsafe fn descriptionWithLocale_indent( &self, locale: Option<&AnyObject>, level: NSUInteger, ) -> Retained<NSString>
NSString only.§Safety
locale should be of the correct type.
pub fn firstObjectCommonWithArray( &self, other_array: &NSArray<ObjectType>, ) -> Option<Retained<ObjectType>>
Sourcepub unsafe fn getObjects_range(
&self,
objects: NonNull<NonNull<ObjectType>>,
range: NSRange,
)
Available on crate feature NSRange only.
pub unsafe fn getObjects_range( &self, objects: NonNull<NonNull<ObjectType>>, range: NSRange, )
NSRange only.§Safety
objects must be a valid pointer.
pub fn indexOfObject(&self, an_object: &ObjectType) -> NSUInteger
pub fn indexOfObject_inRange( &self, an_object: &ObjectType, range: NSRange, ) -> NSUInteger
NSRange only.pub fn indexOfObjectIdenticalTo(&self, an_object: &ObjectType) -> NSUInteger
pub fn indexOfObjectIdenticalTo_inRange( &self, an_object: &ObjectType, range: NSRange, ) -> NSUInteger
NSRange only.pub fn isEqualToArray(&self, other_array: &NSArray<ObjectType>) -> bool
pub fn firstObject(&self) -> Option<Retained<ObjectType>>
pub fn lastObject(&self) -> Option<Retained<ObjectType>>
Sourcepub unsafe fn objectEnumerator(&self) -> Retained<NSEnumerator<ObjectType>>
Available on crate feature NSEnumerator only.
pub unsafe fn objectEnumerator(&self) -> Retained<NSEnumerator<ObjectType>>
NSEnumerator only.§Safety
The returned enumerator’s underlying collection should not be mutated while in use.
Sourcepub unsafe fn reverseObjectEnumerator(
&self,
) -> Retained<NSEnumerator<ObjectType>>
Available on crate feature NSEnumerator only.
pub unsafe fn reverseObjectEnumerator( &self, ) -> Retained<NSEnumerator<ObjectType>>
NSEnumerator only.§Safety
The returned enumerator’s underlying collection should not be mutated while in use.
pub fn sortedArrayHint(&self) -> Retained<NSData>
NSData only.Sourcepub 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( &self, comparator: unsafe extern "C-unwind" fn(NonNull<ObjectType>, NonNull<ObjectType>, *mut c_void) -> NSInteger, context: *mut c_void, ) -> Retained<NSArray<ObjectType>>
§Safety
comparatormust be implemented correctly.contextmust be a valid pointer or null.
Sourcepub 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>>
Available on crate feature NSData only.
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.§Safety
comparatormust be implemented correctly.contextmust be a valid pointer or null.
Sourcepub unsafe fn sortedArrayUsingSelector(
&self,
comparator: Sel,
) -> Retained<NSArray<ObjectType>>
pub unsafe fn sortedArrayUsingSelector( &self, comparator: Sel, ) -> Retained<NSArray<ObjectType>>
§Safety
comparator must be a valid selector.
pub 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.Sourcepub unsafe fn makeObjectsPerformSelector(&self, a_selector: Sel)
pub unsafe fn makeObjectsPerformSelector(&self, a_selector: Sel)
§Safety
a_selector must be a valid selector.
Sourcepub unsafe fn makeObjectsPerformSelector_withObject(
&self,
a_selector: Sel,
argument: Option<&AnyObject>,
)
pub unsafe fn makeObjectsPerformSelector_withObject( &self, a_selector: Sel, argument: Option<&AnyObject>, )
§Safety
a_selectormust be a valid selector.argumentshould be of the correct type.
pub fn objectsAtIndexes( &self, indexes: &NSIndexSet, ) -> Retained<NSArray<ObjectType>>
NSIndexSet only.pub fn objectAtIndexedSubscript(&self, idx: NSUInteger) -> Retained<ObjectType>
pub fn enumerateObjectsUsingBlock( &self, block: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) + '_>, )
block2 only.pub fn enumerateObjectsWithOptions_usingBlock( &self, opts: NSEnumerationOptions, block: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) + '_>, )
NSObjCRuntime and block2 only.pub 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 fn indexOfObjectPassingTest( &self, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_>, ) -> NSUInteger
block2 only.pub fn indexOfObjectWithOptions_passingTest( &self, opts: NSEnumerationOptions, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_>, ) -> NSUInteger
NSObjCRuntime and block2 only.pub 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 fn indexesOfObjectsPassingTest( &self, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NSUInteger, NonNull<Bool>) -> Bool + '_>, ) -> Retained<NSIndexSet>
NSIndexSet and block2 only.pub 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 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.Sourcepub unsafe fn sortedArrayUsingComparator(
&self,
cmptr: NSComparator,
) -> Retained<NSArray<ObjectType>>
Available on crate features NSObjCRuntime and block2 only.
pub unsafe fn sortedArrayUsingComparator( &self, cmptr: NSComparator, ) -> Retained<NSArray<ObjectType>>
NSObjCRuntime and block2 only.§Safety
cmptr must be a valid pointer.
Sourcepub unsafe fn sortedArrayWithOptions_usingComparator(
&self,
opts: NSSortOptions,
cmptr: NSComparator,
) -> Retained<NSArray<ObjectType>>
Available on crate features NSObjCRuntime and block2 only.
pub unsafe fn sortedArrayWithOptions_usingComparator( &self, opts: NSSortOptions, cmptr: NSComparator, ) -> Retained<NSArray<ObjectType>>
NSObjCRuntime and block2 only.§Safety
cmptr must be a valid pointer.
Sourcepub unsafe fn indexOfObject_inSortedRange_options_usingComparator(
&self,
obj: &ObjectType,
r: NSRange,
opts: NSBinarySearchingOptions,
cmp: NSComparator,
) -> NSUInteger
Available on crate features NSObjCRuntime and NSRange 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.§Safety
cmp must be a valid pointer.
pub 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 fn differenceFromArray_withOptions( &self, other: &NSArray<ObjectType>, options: NSOrderedCollectionDifferenceCalculationOptions, ) -> Retained<NSOrderedCollectionDifference<ObjectType>>
NSOrderedCollectionDifference only.pub fn differenceFromArray( &self, other: &NSArray<ObjectType>, ) -> Retained<NSOrderedCollectionDifference<ObjectType>>
NSOrderedCollectionDifference only.pub fn arrayByApplyingDifference( &self, difference: &NSOrderedCollectionDifference<ObjectType>, ) -> Option<Retained<NSArray<ObjectType>>>
NSOrderedCollectionDifference only.Sourcepub unsafe fn getObjects(&self, objects: NonNull<NonNull<ObjectType>>)
👎Deprecated: Use -getObjects:range: instead
pub unsafe fn getObjects(&self, objects: NonNull<NonNull<ObjectType>>)
§Safety
objects must be a valid pointer.
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 fn valueForKey(&self, key: &NSString) -> Retained<AnyObject>
NSKeyValueCoding and NSString only.Sourcepub unsafe fn setValue_forKey(&self, value: Option<&AnyObject>, key: &NSString)
Available on crate features NSKeyValueCoding and NSString only.
pub unsafe fn setValue_forKey(&self, value: Option<&AnyObject>, key: &NSString)
NSKeyValueCoding and NSString only.§Safety
value should be of the correct type.
Sourcepub unsafe fn addObserver_toObjectsAtIndexes_forKeyPath_options_context(
&self,
observer: &NSObject,
indexes: &NSIndexSet,
key_path: &NSString,
options: NSKeyValueObservingOptions,
context: *mut c_void,
)
Available on crate features NSKeyValueObserving and NSIndexSet 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.§Safety
observershould be of the correct type.contextmust be a valid pointer or null.
Sourcepub unsafe fn removeObserver_fromObjectsAtIndexes_forKeyPath_context(
&self,
observer: &NSObject,
indexes: &NSIndexSet,
key_path: &NSString,
context: *mut c_void,
)
Available on crate features 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.§Safety
observershould be of the correct type.contextmust be a valid pointer or null.
Sourcepub unsafe fn removeObserver_fromObjectsAtIndexes_forKeyPath(
&self,
observer: &NSObject,
indexes: &NSIndexSet,
key_path: &NSString,
)
Available on crate features 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.§Safety
observer should be of the correct type.
Sourcepub unsafe fn addObserver_forKeyPath_options_context(
&self,
observer: &NSObject,
key_path: &NSString,
options: NSKeyValueObservingOptions,
context: *mut c_void,
)
Available on crate features NSKeyValueObserving 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.§Safety
observershould be of the correct type.contextmust be a valid pointer or null.
Sourcepub unsafe fn removeObserver_forKeyPath_context(
&self,
observer: &NSObject,
key_path: &NSString,
context: *mut c_void,
)
Available on crate features NSKeyValueObserving and NSString only.
pub unsafe fn removeObserver_forKeyPath_context( &self, observer: &NSObject, key_path: &NSString, context: *mut c_void, )
NSKeyValueObserving and NSString only.§Safety
observershould be of the correct type.contextmust be a valid pointer or null.
Sourcepub unsafe fn removeObserver_forKeyPath(
&self,
observer: &NSObject,
key_path: &NSString,
)
Available on crate features NSKeyValueObserving and NSString only.
pub unsafe fn removeObserver_forKeyPath( &self, observer: &NSObject, key_path: &NSString, )
NSKeyValueObserving and NSString only.§Safety
observer should be of the correct type.
pub fn pathsMatchingExtensions( &self, filter_types: &NSArray<NSString>, ) -> Retained<NSArray<NSString>>
NSPathUtilities and NSString only.pub fn filteredArrayUsingPredicate( &self, predicate: &NSPredicate, ) -> Retained<NSArray<ObjectType>>
NSPredicate only.pub 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<CFMutableArray<ObjectType>> for NSMutableArray<ObjectType>
Available on crate feature objc2-core-foundation only.
impl<ObjectType: ?Sized + Message> AsRef<CFMutableArray<ObjectType>> for NSMutableArray<ObjectType>
objc2-core-foundation only.Source§fn as_ref(&self) -> &CFMutableArray<ObjectType>
fn as_ref(&self) -> &CFMutableArray<ObjectType>
Source§impl<ObjectType: ?Sized + Message> AsRef<NSMutableArray<ObjectType>> for CFMutableArray<ObjectType>
Available on crate feature objc2-core-foundation only.
impl<ObjectType: ?Sized + Message> AsRef<NSMutableArray<ObjectType>> for CFMutableArray<ObjectType>
objc2-core-foundation only.Source§fn as_ref(&self) -> &NSMutableArray<ObjectType>
fn as_ref(&self) -> &NSMutableArray<ObjectType>
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_refSource§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.