Creates and returns a set containing the objects in a given argument list.
SDKs
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
+ (instancetype)setWithObjects:(Object Type)firstObj, ...;
Parameters
firstObj
The first object to add to the new set.
firstObj, ...
A comma-separated list of objects, ending with
nil
, to add to the new set. If the same object appears more than once in the list of objects, it is added only once to the returned set. Each object receives aretain
message as it is added to the set.
Return Value
A new set containing the objects in the argument list.
Discussion
As an example, the following code excerpt creates a set containing three different types of elements (assuming a
exits):
NSSet *mySet;
NSData *someData = [NSData dataWithContentsOfFile:aPath];
NSValue *aValue = [NSNumber numberWithInteger:5];
NSString *aString = @"a string";
mySet = [NSSet setWithObjects:someData, aValue, aString, nil];