Data sotrage NSSet and NSMutableSet - Objective C
NSSet & NSMutableSet
NSSet is used to hold an immutable set of distinct objects and the NSMutaableDictionary is used to hold an mutable set of distinct object.
Important methods of NSSet are as follows:
Important methods of NSMutableSet are as follows:
Example
Now when we compile and run the program we will get the following result:
NSSet is used to hold an immutable set of distinct objects and the NSMutaableDictionary is used to hold an mutable set of distinct object.
Important methods of NSSet are as follows:
- alloc/initWithObjcts: initialize a newly allocated set with members taken from the specified list of objects.
- allObjects: return an array containing the set's members or an empty array if the set has no members.
- count: return the number of member in the set.
Important methods of NSMutableSet are as follows:
- removeAllObjects : Empties theset of all of its members
- addObject : Adds a given object to the set , if it is not already a member
- removeObject : Removes a given object from the set
Example
#import <Foundation/Foundation.h>
int main()
{
NSSet *setobj = [[NSSet alloc]initWithObjects : @"raj", @"ram",@"rahul",nil];
NSArray *setarrobj = [setobj allObjects];
NSLog(@"The object in set are %@", setarrobj);
NSMutableSet *mutsetobj = [[NSMutableSet alloc]init];
[mutsetobj addObject : @"sunena"];
setarrobj = [ mutsetobj allObjects];
NSLog(@"The object in mutable set are %@", setarrobj);
return 0;
}
int main()
{
NSSet *setobj = [[NSSet alloc]initWithObjects : @"raj", @"ram",@"rahul",nil];
NSArray *setarrobj = [setobj allObjects];
NSLog(@"The object in set are %@", setarrobj);
NSMutableSet *mutsetobj = [[NSMutableSet alloc]init];
[mutsetobj addObject : @"sunena"];
setarrobj = [ mutsetobj allObjects];
NSLog(@"The object in mutable set are %@", setarrobj);
return 0;
}
Now when we compile and run the program we will get the following result:
No comments: