#[repr(C)]pub struct NSMutableSet<ObjectType: ?Sized = AnyObject> { /* private fields */ }
NSSet
only.Expand description
************** Mutable Set ***************
See also Apple’s documentation
Implementations§
Source§impl<ObjectType: Message> NSMutableSet<ObjectType>
NSPredicateSupport.
impl<ObjectType: Message> NSMutableSet<ObjectType>
NSPredicateSupport.
pub unsafe fn filterUsingPredicate(&self, predicate: &NSPredicate)
NSPredicate
only.Source§impl<ObjectType: Message> NSMutableSet<ObjectType>
Methods declared on superclass NSSet
.
impl<ObjectType: Message> NSMutableSet<ObjectType>
Methods declared on superclass NSSet
.
NSSetCreation.
pub unsafe fn set() -> Retained<Self>
pub unsafe fn setWithObject(object: &ObjectType) -> Retained<Self>
pub unsafe fn setWithObjects_count( objects: NonNull<NonNull<ObjectType>>, cnt: NSUInteger, ) -> Retained<Self>
pub unsafe fn setWithSet(set: &NSSet<ObjectType>) -> Retained<Self>
pub unsafe fn setWithArray(array: &NSArray<ObjectType>) -> Retained<Self>
NSArray
only.pub unsafe fn initWithSet( this: Allocated<Self>, set: &NSSet<ObjectType>, ) -> Retained<Self>
pub unsafe fn initWithSet_copyItems( this: Allocated<Self>, set: &NSSet<ObjectType>, flag: bool, ) -> Retained<Self>
pub unsafe fn initWithArray( this: Allocated<Self>, array: &NSArray<ObjectType>, ) -> Retained<Self>
NSArray
only.Source§impl<ObjectType: Message> NSMutableSet<ObjectType>
impl<ObjectType: Message> NSMutableSet<ObjectType>
pub fn addObject(&self, object: &ObjectType)
pub fn removeObject(&self, object: &ObjectType)
pub unsafe fn initWithCoder( this: Allocated<Self>, coder: &NSCoder, ) -> Option<Retained<Self>>
NSCoder
only.pub fn init(this: Allocated<Self>) -> Retained<Self>
pub fn initWithCapacity( this: Allocated<Self>, num_items: NSUInteger, ) -> Retained<Self>
Source§impl<ObjectType: Message> NSMutableSet<ObjectType>
Methods declared on superclass NSSet
.
impl<ObjectType: Message> NSMutableSet<ObjectType>
Methods declared on superclass NSSet
.
pub unsafe fn initWithObjects_count( this: Allocated<Self>, objects: *mut NonNull<ObjectType>, cnt: NSUInteger, ) -> Retained<Self>
Source§impl<ObjectType: Message> NSMutableSet<ObjectType>
Methods declared on superclass NSObject
.
impl<ObjectType: Message> NSMutableSet<ObjectType>
Methods declared on superclass NSObject
.
Source§impl<ObjectType: Message> NSMutableSet<ObjectType>
NSExtendedMutableSet.
impl<ObjectType: Message> NSMutableSet<ObjectType>
NSExtendedMutableSet.
pub unsafe fn addObjectsFromArray(&self, array: &NSArray<ObjectType>)
NSArray
only.pub unsafe fn intersectSet(&self, other_set: &NSSet<ObjectType>)
pub unsafe fn minusSet(&self, other_set: &NSSet<ObjectType>)
pub fn removeAllObjects(&self)
pub unsafe fn unionSet(&self, other_set: &NSSet<ObjectType>)
pub unsafe fn setSet(&self, other_set: &NSSet<ObjectType>)
Source§impl<ObjectType: Message> NSMutableSet<ObjectType>
NSMutableSetCreation.
impl<ObjectType: Message> NSMutableSet<ObjectType>
NSMutableSetCreation.
pub unsafe fn setWithCapacity(num_items: NSUInteger) -> Retained<Self>
Source§impl<ObjectType: Message> NSMutableSet<ObjectType>
Convenience creation methods.
impl<ObjectType: Message> NSMutableSet<ObjectType>
Convenience creation methods.
Sourcepub fn from_retained_slice(slice: &[Retained<ObjectType>]) -> Retained<Self>
pub fn from_retained_slice(slice: &[Retained<ObjectType>]) -> Retained<Self>
Creates an NSMutableSet
from a slice of Retained
s.
§Examples
use objc2_foundation::{NSMutableSet, NSString};
let strs = ["one", "two", "three"].map(NSString::from_str);
let set = NSMutableSet::from_retained_slice(&strs);
pub fn from_slice(slice: &[&ObjectType]) -> Retained<Self>
Methods from Deref<Target = NSSet<ObjectType>>§
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_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 filteredSetUsingPredicate( &self, predicate: &NSPredicate, ) -> Retained<NSSet<ObjectType>>
NSPredicate
only.pub fn count(&self) -> NSUInteger
pub fn member(&self, object: &ObjectType) -> Option<Retained<ObjectType>>
pub unsafe fn objectEnumerator(&self) -> Retained<NSEnumerator<ObjectType>>
NSEnumerator
only.pub fn allObjects(&self) -> Retained<NSArray<ObjectType>>
NSArray
only.pub fn anyObject(&self) -> Option<Retained<ObjectType>>
pub 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 fn intersectsSet(&self, other_set: &NSSet<ObjectType>) -> bool
pub unsafe fn isEqualToSet(&self, other_set: &NSSet<ObjectType>) -> bool
pub fn isSubsetOfSet(&self, other_set: &NSSet<ObjectType>) -> bool
pub unsafe fn makeObjectsPerformSelector(&self, a_selector: Sel)
pub unsafe fn makeObjectsPerformSelector_withObject( &self, a_selector: Sel, argument: Option<&AnyObject>, )
pub unsafe fn setByAddingObject( &self, an_object: &ObjectType, ) -> Retained<NSSet<ObjectType>>
pub unsafe fn setByAddingObjectsFromSet( &self, other: &NSSet<ObjectType>, ) -> Retained<NSSet<ObjectType>>
pub unsafe fn setByAddingObjectsFromArray( &self, other: &NSArray<ObjectType>, ) -> Retained<NSSet<ObjectType>>
NSArray
only.pub unsafe fn enumerateObjectsUsingBlock( &self, block: &DynBlock<dyn Fn(NonNull<ObjectType>, NonNull<Bool>) + '_>, )
block2
only.pub unsafe fn enumerateObjectsWithOptions_usingBlock( &self, opts: NSEnumerationOptions, block: &DynBlock<dyn Fn(NonNull<ObjectType>, NonNull<Bool>) + '_>, )
NSObjCRuntime
and block2
only.pub unsafe fn objectsPassingTest( &self, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NonNull<Bool>) -> Bool + '_>, ) -> Retained<NSSet<ObjectType>>
block2
only.pub unsafe fn objectsWithOptions_passingTest( &self, opts: NSEnumerationOptions, predicate: &DynBlock<dyn Fn(NonNull<ObjectType>, NonNull<Bool>) -> Bool + '_>, ) -> Retained<NSSet<ObjectType>>
NSObjCRuntime
and block2
only.pub unsafe fn sortedArrayUsingDescriptors( &self, sort_descriptors: &NSArray<NSSortDescriptor>, ) -> Retained<NSArray<ObjectType>>
NSSortDescriptor
and NSArray
only.Sourcepub unsafe fn anyObject_unchecked(&self) -> Option<&ObjectType>
pub unsafe fn anyObject_unchecked(&self) -> Option<&ObjectType>
Sourcepub unsafe fn member_unchecked(
&self,
object: &ObjectType,
) -> Option<&ObjectType>
pub unsafe fn member_unchecked( &self, object: &ObjectType, ) -> Option<&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 len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the set.
§Examples
use objc2_foundation::{ns_string, NSSet};
let strs = [ns_string!("one"), ns_string!("two"), ns_string!("three")];
let set = NSSet::from_slice(&strs);
assert_eq!(set.len(), 3);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the set contains no elements.
§Examples
use objc2_foundation::{NSSet, NSObject};
let set = NSSet::<NSObject>::new();
assert!(set.is_empty());
Sourcepub fn iter(&self) -> Iter<'_, ObjectType> ⓘ
Available on crate feature NSEnumerator
only.
pub fn iter(&self) -> Iter<'_, ObjectType> ⓘ
NSEnumerator
only.An iterator visiting all elements in arbitrary order.
§Examples
use objc2_foundation::{ns_string, NSSet};
let set = NSSet::from_slice(&[ns_string!("one"), ns_string!("two"), ns_string!("three")]);
for s in set.iter() {
println!("{s}");
}
Sourcepub fn to_vec(&self) -> Vec<Retained<ObjectType>>
Available on crate feature NSEnumerator
only.
pub fn to_vec(&self) -> Vec<Retained<ObjectType>>
NSEnumerator
only.Returns a Vec
containing the set’s elements in arbitrary order.
§Examples
use objc2_foundation::{NSSet, NSString};
let strs = [
NSString::from_str("one"),
NSString::from_str("two"),
NSString::from_str("three"),
];
let set = NSSet::from_retained_slice(&strs);
let vec = set.to_vec();
assert_eq!(vec.len(), 3);
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<NSMutableSet<ObjectType>> for NSCountedSet<ObjectType>
impl<ObjectType: ?Sized + Message> AsRef<NSMutableSet<ObjectType>> for NSCountedSet<ObjectType>
Source§fn as_ref(&self) -> &NSMutableSet<ObjectType>
fn as_ref(&self) -> &NSMutableSet<ObjectType>
Source§impl<ObjectType: ?Sized + Message> AsRef<NSMutableSet<ObjectType>> for NSMutableSet<ObjectType>
impl<ObjectType: ?Sized + Message> AsRef<NSMutableSet<ObjectType>> for NSMutableSet<ObjectType>
Source§impl<ObjectType: ?Sized + Message> Borrow<NSMutableSet<ObjectType>> for NSCountedSet<ObjectType>
impl<ObjectType: ?Sized + Message> Borrow<NSMutableSet<ObjectType>> for NSCountedSet<ObjectType>
Source§fn borrow(&self) -> &NSMutableSet<ObjectType>
fn borrow(&self) -> &NSMutableSet<ObjectType>
Source§impl<ObjectType: ?Sized + Message> ClassType for NSMutableSet<ObjectType>
impl<ObjectType: ?Sized + Message> ClassType for NSMutableSet<ObjectType>
Source§const NAME: &'static str = "NSMutableSet"
const NAME: &'static str = "NSMutableSet"
Source§type ThreadKind = <<NSMutableSet<ObjectType> as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSMutableSet<ObjectType> as ClassType>::Super as ClassType>::ThreadKind
Source§impl<ObjectType: ?Sized + Message> CopyingHelper for NSMutableSet<ObjectType>
Available on crate feature NSObject
only.
impl<ObjectType: ?Sized + Message> CopyingHelper for NSMutableSet<ObjectType>
NSObject
only.Source§impl<ObjectType: Debug + Message> Debug for NSMutableSet<ObjectType>
Available on crate feature NSEnumerator
only.
impl<ObjectType: Debug + Message> Debug for NSMutableSet<ObjectType>
NSEnumerator
only.Source§impl<ObjectType: Message> DefaultRetained for NSMutableSet<ObjectType>
impl<ObjectType: Message> DefaultRetained for NSMutableSet<ObjectType>
Source§impl<'a, ObjectType: Message> Extend<&'a ObjectType> for &NSMutableSet<ObjectType>
impl<'a, ObjectType: Message> Extend<&'a ObjectType> for &NSMutableSet<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 &NSMutableSet<ObjectType>
impl<ObjectType: Message> Extend<Retained<ObjectType>> for &NSMutableSet<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 NSMutableSet<ObjectType>
impl<ObjectType: ?Sized> Hash for NSMutableSet<ObjectType>
Source§impl<'a, ObjectType: Message> IntoIterator for &'a NSMutableSet<ObjectType>
impl<'a, ObjectType: Message> IntoIterator for &'a NSMutableSet<ObjectType>
Source§impl<ObjectType: ?Sized + Message> MutableCopyingHelper for NSMutableSet<ObjectType>
Available on crate feature NSObject
only.
impl<ObjectType: ?Sized + Message> MutableCopyingHelper for NSMutableSet<ObjectType>
NSObject
only.Source§type Result = NSMutableSet<ObjectType>
type Result = NSMutableSet<ObjectType>
Self
if the type has no
mutable counterpart. Read moreSource§impl<ObjectType: ?Sized + NSCoding> NSCoding for NSMutableSet<ObjectType>
impl<ObjectType: ?Sized + NSCoding> NSCoding for NSMutableSet<ObjectType>
Source§unsafe fn encodeWithCoder(&self, coder: &NSCoder)
unsafe fn encodeWithCoder(&self, coder: &NSCoder)
NSObject
and NSCoder
only.Source§impl<ObjectType: ?Sized> NSCopying for NSMutableSet<ObjectType>
impl<ObjectType: ?Sized> NSCopying for NSMutableSet<ObjectType>
Source§impl<ObjectType: ?Sized> NSFastEnumeration for NSMutableSet<ObjectType>
impl<ObjectType: ?Sized> NSFastEnumeration for NSMutableSet<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 NSMutableSet<ObjectType>
impl<ObjectType: ?Sized> NSMutableCopying for NSMutableSet<ObjectType>
Source§impl<ObjectType: ?Sized> NSObjectProtocol for NSMutableSet<ObjectType>
impl<ObjectType: ?Sized> NSObjectProtocol for NSMutableSet<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 NSMutableSet<ObjectType>
impl<ObjectType: ?Sized + NSSecureCoding> NSSecureCoding for NSMutableSet<ObjectType>
Source§impl<ObjectType: ?Sized> PartialEq for NSMutableSet<ObjectType>
impl<ObjectType: ?Sized> PartialEq for NSMutableSet<ObjectType>
Source§impl<ObjectType: ?Sized + Message> RefEncode for NSMutableSet<ObjectType>
impl<ObjectType: ?Sized + Message> RefEncode for NSMutableSet<ObjectType>
Source§const ENCODING_REF: Encoding = <NSSet<ObjectType> as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <NSSet<ObjectType> as ::objc2::RefEncode>::ENCODING_REF
Source§impl<'a, ObjectType: Message + 'a> RetainedFromIterator<&'a ObjectType> for NSMutableSet<ObjectType>
impl<'a, ObjectType: Message + 'a> RetainedFromIterator<&'a ObjectType> for NSMutableSet<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 NSMutableSet<ObjectType>
impl<ObjectType: Message> RetainedFromIterator<Retained<ObjectType>> for NSMutableSet<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 NSMutableSet<ObjectType>
impl<ObjectType: Message> RetainedIntoIterator for NSMutableSet<ObjectType>
Source§impl<ObjectType: Message> ToOwned for NSMutableSet<ObjectType>
Available on crate feature NSObject
only.
impl<ObjectType: Message> ToOwned for NSMutableSet<ObjectType>
NSObject
only.