Class: NSSet
Overview
The NSSet, NSMutableSet, and NSCountedSet classes declare the programmatic interface to an unordered collection of objects.
Direct Known Subclasses
Class Method Summary (collapse)
-
+ set
Creates and returns an empty set.
-
+ setWithArray:
Creates and returns a set containing a uniqued collection of the objects contained in a given array.
-
+ setWithObject:
Creates and returns a set that contains a single given object.
-
+ setWithObjects:
Creates and returns a set containing the objects in a given argument list.
-
+ setWithObjects:count:
Creates and returns a set containing a specified number of objects from a given C array of objects.
-
+ setWithSet:
Creates and returns a set containing the objects from another set.
Instance Method Summary (collapse)
-
- addObserver:forKeyPath:options:context:
Raises an exception.
-
- allObjects
Returns an array containing the set’s members, or an empty array if the set has no members.
-
- anyObject
Returns one of the objects in the set, or nil if the set contains no objects.
-
- containsObject:
Returns a Boolean value that indicates whether a given object is present in the set.
-
- count
Returns the number of members in the set.
-
- description
Returns a string that represents the contents of the set, formatted as a property list.
-
- descriptionWithLocale:
Returns a string that represents the contents of the set, formatted as a property list.
-
- enumerateObjectsUsingBlock:
Executes a given Block using each object in the set.
-
- enumerateObjectsWithOptions:usingBlock:
Executes a given Block using each object in the set, using the specified enumeration options.
-
- filteredSetUsingPredicate:
Evaluates a given predicate against each object in the receiving set and returns a new set containing the objects for which the predicate returns true.
-
- initWithArray:
Initializes a newly allocated set with the objects that are contained in a given array.
-
- initWithObjects:
Initializes a newly allocated set with members taken from the specified list of objects.
-
- initWithObjects:count:
Initializes a newly allocated set with a specified number of objects from a given C array of objects.
-
- initWithSet:
Initializes a newly allocated set and adds to it objects from another given set.
-
- initWithSet:copyItems:
Initializes a newly allocated set and adds to it members of another given set.
-
- intersectsSet:
Returns a Boolean value that indicates whether at least one object in the receiving set is also present in another given set.
-
- isEqualToSet:
Compares the receiving set to another set.
-
- isSubsetOfSet:
Returns a Boolean value that indicates whether every object in the receiving set is also present in another given set.
-
- makeObjectsPerformSelector:
Sends a message specified by a given selector to each object in the set.
-
- makeObjectsPerformSelector:withObject:
Sends a message specified by a given selector to each object in the set.
-
- member:
Determines whether the set contains an object equal to a given object, and returns that object if it is present.
-
- objectEnumerator
Returns an enumerator object that lets you access each object in the set.
-
- objectsPassingTest:
Returns a set of object that pass a test in a given Block.
-
- objectsWithOptions:passingTest:
Returns a set of object that pass a test in a given Block, using the specified enumeration options.
-
- removeObserver:forKeyPath:
Raises an exception.
-
- setByAddingObject:
Returns a new set formed by adding a given object to the receiving set.
-
- setByAddingObjectsFromArray:
Returns a new set formed by adding the objects in a given array to the receiving set.
-
- setByAddingObjectsFromSet:
Returns a new set formed by adding the objects in a given set to the receiving set.
-
- setValue:forKey:
Invokes setValue:forKey: on each of the set’s members.
-
- sortedArrayUsingDescriptors:
Returns an array of the set’s content sorted as specified by a given array of sort descriptors.
-
- valueForKey:
Return a set containing the results of invoking valueForKey: on each of the receiving set’s members.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (Object) set
Creates and returns an empty set. This method is declared primarily for the use of mutable subclasses of NSSet.
+ (Object) setWithArray(array)
Creates and returns a set containing a uniqued collection of the objects contained in a given array.
+ (Object) setWithObject(object)
Creates and returns a set that contains a single given object.
+ (Object) setWithObjects(firstObj, ...)
Creates and returns a set containing the objects in a given argument list. As an example, the following code excerpt creates a set containing three different types of elements (assuming aPath exits):
+ (Object) setWithObjects(objects, count:cnt)
Creates and returns a set containing a specified number of objects from a given C array of objects.
+ (Object) setWithSet(set)
Creates and returns a set containing the objects from another set.
Instance Method Details
- (Object) addObserver(observer, forKeyPath:keyPath, options:options, context:context)
Raises an exception.
- (Array) allObjects
Returns an array containing the set’s members, or an empty array if the set has no members.
- (Object) anyObject
Returns one of the objects in the set, or nil if the set contains no objects.
- (Boolean) containsObject(anObject)
Returns a Boolean value that indicates whether a given object is present in the set.
- (Integer) count
Returns the number of members in the set.
- (String) description
Returns a string that represents the contents of the set, formatted as a property list.
- (String) descriptionWithLocale(locale)
Returns a string that represents the contents of the set, formatted as a property list. This method sends each of the set’s members descriptionWithLocale: with locale passed as the sole parameter. If the set’s members do not respond to descriptionWithLocale:, this method sends description instead.
- (Object) enumerateObjectsUsingBlock(block)
Executes a given Block using each object in the set.
- (Object) enumerateObjectsWithOptions(opts, usingBlock:block)
Executes a given Block using each object in the set, using the specified enumeration options.
- (NSSet) filteredSetUsingPredicate(predicate)
Evaluates a given predicate against each object in the receiving set and returns a new set containing the objects for which the predicate returns true. The following example illustrates the use of this method.
- (Object) initWithArray(array)
Initializes a newly allocated set with the objects that are contained in a given array.
- (Object) initWithObjects(firstObj, ...)
Initializes a newly allocated set with members taken from the specified list of objects.
- (Object) initWithObjects(objects, count:cnt)
Initializes a newly allocated set with a specified number of objects from a given C array of objects. This method is the designated initializer for NSSet.
- (Object) initWithSet(set)
Initializes a newly allocated set and adds to it objects from another given set.
- (Object) initWithSet(set, copyItems:flag)
Initializes a newly allocated set and adds to it members of another given set. After an immutable s has been initialized in this way, it cannot be modified.The copyWithZone: method performs a shallow copy. If you have a collection of arbitrary depth, passing YES for the flag parameter will perform an immutable copy of the first level below the surface. If you pass NO the mutability of the first level is unaffected. In either case, the mutability of all deeper levels is unaffected.
- (Boolean) intersectsSet(otherSet)
Returns a Boolean value that indicates whether at least one object in the receiving set is also present in another given set.
- (Boolean) isEqualToSet(otherSet)
Compares the receiving set to another set. Two sets have equal contents if they each have the same number of members and if each member of one set is present in the other.
- (Boolean) isSubsetOfSet(otherSet)
Returns a Boolean value that indicates whether every object in the receiving set is also present in another given set.
- (Object) makeObjectsPerformSelector(aSelector)
Sends a message specified by a given selector to each object in the set. The message specified by aSelector is sent once to each member of the set. This method raises an NSInvalidArgumentException if aSelector is NULL.
- (Object) makeObjectsPerformSelector(aSelector, withObject:argument)
Sends a message specified by a given selector to each object in the set. The message specified by aSelector is sent, with argument as the argument, once to each member of the set. This method raises an NSInvalidArgumentException if aSelector is NULL.
- (Object) member(object)
Determines whether the set contains an object equal to a given object, and returns that object if it is present. If you override isEqual:, you must also override the hash method for the member: method to work on a set of objects of your class.
- (NSEnumerator) objectEnumerator
Returns an enumerator object that lets you access each object in the set. The following code fragment illustrates how you can use this method. When this method is used with mutable subclasses of NSSet, your code shouldn’t modify the set during enumeration. If you intend to modify the set, use the allObjects method to create a “snapshot” of the set’s members. Enumerate the snapshot, but make your modifications to the original set.
- (NSSet) objectsPassingTest(predicate)
Returns a set of object that pass a test in a given Block.
- (NSSet) objectsWithOptions(opts, passingTest:predicate)
Returns a set of object that pass a test in a given Block, using the specified enumeration options.
- (Object) removeObserver(observer, forKeyPath:keyPath)
Raises an exception.
- (NSSet) setByAddingObject(anObject)
Returns a new set formed by adding a given object to the receiving set.
- (NSSet) setByAddingObjectsFromArray(other)
Returns a new set formed by adding the objects in a given array to the receiving set.
- (NSSet) setByAddingObjectsFromSet(other)
Returns a new set formed by adding the objects in a given set to the receiving set.
- (Object) setValue(value, forKey:key)
Invokes setValue:forKey: on each of the set’s members.
- (Array) sortedArrayUsingDescriptors(sortDescriptors)
Returns an array of the set’s content sorted as specified by a given array of sort descriptors. The first descriptor specifies the primary key path to be used in sorting the set’s contents. Any subsequent descriptors are used to further refine sorting of objects with duplicate values. See NSSortDescriptor for additional information.
- (Object) valueForKey(key)
Return a set containing the results of invoking valueForKey: on each of the receiving set’s members. The returned set might not have the same number of members as the receiving set. The returned set will not contain any elements corresponding to instances of valueForKey: returning nil (note that this is in contrast with NSArray’s implementation, which may put NSNull values in the arrays it returns).