![]() |
NSSet and NSMutableSet are two classes in Objective-C that are used for representing collections of objects. Both classes provide an ordered set of unique objects, with the difference being that NSSet is immutable, while NSMutableSet is mutable, which means its contents can be changed dynamically. In this article, we will be exploring the NSSet and NSMutableSet classes in detail. NSSetNSSet is a class that represents an unordered collection of unique objects. The objects stored in a set must be of the same type and cannot be duplicated. NSSet provides several methods for adding, removing, and searching for objects, as well as for determining the number of objects in the set and checking for the presence of specific objects. Syntax: In Objective-C, creating a set is done using the NSSet classes. To create an instance of NSSet, the following syntax can be used:
NSMutableSetNSMutableSet is a subclass of NSSet and provides the same functionality as NSSet, with the addition of the ability to modify its contents. NSMutableSet provides methods for adding and removing objects, as well as for removing all objects from the set. Syntax: In Objective-C, creating a set is done using the NSMutableSet classes. To create an instance of NSMutableSet, the following syntax can be used:
Below is a table showing some of the commonly used methods of NSSet and NSMutableSet with their descriptions:
Example 1: Introduction to NSMutableSet. ObjectiveC
Output: ![]()
The above code creates an empty NSMutableSet and adds three objects to it. The contents of the set are then printed using NSLog. Example 2: Creating an NSSet and NSMutableSet ObjectiveC
Output: ![]()
In the first part of the example, an NSSet is created with three objects, and its contents are printed using NSLog. In the second part, an NSMutableSet is created with the same three objects as the NSSet, and an additional object “Date” is added to it. The contents of the NSMutableSet are then printed using NSLog. |
Reffered: https://www.geeksforgeeks.org
Objective C |
Related |
---|
|
![]() |
![]() |
|
|
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |