Advertisements
NSMutableOrderedSet by example
Creating a Mutable Ordered Set
+ orderedSetWithCapacity:
Creates and returns an mutable ordered set with a given initial capacity.
Example
NSMutableOrderedSet *orderedSet = [NSMutableOrderedSet orderedSetWithCapacity:5]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:09:03.744 iOS-Tutorial[2021:a0b] {( )}
- initWithCapacity:
Returns an initialized mutable ordered set with a given initial capacity.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]initWithCapacity:5]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:09:03.744 iOS-Tutorial[2021:a0b] {( )}
- init
Initializes a newly allocated mutable ordered set.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:09:03.744 iOS-Tutorial[2021:a0b] {( )}
Adding, Removing, and Reordering Entries
- addObject:
Appends a given object to the mutable ordered set, if it is not already a member.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObject:@"Eezy"]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:10:58.818 iOS-Tutorial[2043:a0b] {( Eezy )}
- addObjects:count:
Appends the given number of objects from a given C array.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; id objects[] = {@"Eezy", @"Tutorials"}; [orderedSet addObjects:objects count:2]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:14:11.752 iOS-Tutorial[2059:a0b] {( Eezy, Tutorials )}
- addObjectsFromArray:
Appends to the mutable ordered set each object contained in a given array that is not already a member.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:14:58.805 iOS-Tutorial[2080:a0b] {( Eezy, Tutorials )}
- insertObject:atIndex:
Inserts the given object at the specified index of the mutable ordered set.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet insertObject:@"Eezy" atIndex:0]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:15:40.888 iOS-Tutorial[2097:a0b] {( Eezy )}
- setObject:atIndexedSubscript:
Inserts the given object at the specified index of the mutable ordered set.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet setObject:@"Eezy" atIndexedSubscript:0]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:16:35.556 iOS-Tutorial[2109:a0b] {( Eezy )}
- insertObjects:atIndexes:
Inserts the objects in the array at the specified indexes.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet insertObjects:@[@"Eezy", @"Tutorials"] atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)]]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:17:56.575 iOS-Tutorial[2121:a0b] {( Eezy, Tutorials )}
- removeObject:
Removes a given object from the mutable ordered set.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet removeObject:@"Eezy"]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:19:17.334 iOS-Tutorial[2135:a0b] {( Tutorials )}
- removeObjectAtIndex:
Removes a the object at the specified index from the mutable ordered set.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet removeObjectAtIndex:0]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:19:17.334 iOS-Tutorial[2135:a0b] {( Tutorials )}
- removeObjectsAtIndexes:
Removes the objects at the specified indexes from the mutable ordered set.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet removeObjectsAtIndexes:[NSIndexSet indexSetWithIndex:0]]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:20:24.145 iOS-Tutorial[2149:a0b] {( Tutorials )}
- removeObjectsInArray:
Removes the objects in the array from the mutable ordered set.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet removeObjectsInArray:@[@"Eezy"]]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:21:01.913 iOS-Tutorial[2170:a0b] {( Tutorials )}
- removeObjectsInRange:
Removes from the mutable ordered set each of the objects within a given range.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet removeObjectsInRange:NSMakeRange(1, 1)]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:21:31.930 iOS-Tutorial[2188:a0b] {( Eezy )}
- removeAllObjects
Removes all the objects from the mutable ordered set.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet removeAllObjects]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:21:56.505 iOS-Tutorial[2203:a0b] {( )}
replaceObjectAtIndex:withObject:
Replaces the object at the specified index with the new object.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet replaceObjectAtIndex:1 withObject:@"iOS"]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:22:38.705 iOS-Tutorial[2220:a0b] {( Eezy, iOS )}
replaceObjectsAtIndexes:withObjects:
Replaces the objects at the specified indexes with the new objects.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet replaceObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)] withObjects:@[@"iOS", @"Coding"]]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:24:42.087 iOS-Tutorial[2255:a0b] {( iOS, Coding )}
- replaceObjectsInRange:withObjects:count:
Replaces the objects in the receiving mutable ordered set at the range with the specified number of objects from a given C array.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; id objects[] = {@"iOS",@"Coding"}; [orderedSet replaceObjectsInRange:NSMakeRange(0, 2) withObjects:objects count:2]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:26:29.578 iOS-Tutorial[2273:a0b] {( iOS, Coding )}
- setObject:atIndex:
Appends or replaces the object at the specified index.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet setObject:@"iOS" atIndex:2]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:27:23.592 iOS-Tutorial[2291:a0b] {( Eezy, Tutorials, iOS )}
- moveObjectsAtIndexes:toIndex:
Moves the objects at the specified indexes to the new location.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet moveObjectsAtIndexes:[NSIndexSet indexSetWithIndex:1] toIndex:0]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:30:18.893 iOS-Tutorial[2326:a0b] {( Tutorials, Eezy )}
- exchangeObjectAtIndex:withObjectAtIndex:
Exchanges the object at the specified index with the object at the other index.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet exchangeObjectAtIndex:0 withObjectAtIndex:1]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:30:52.072 iOS-Tutorial[2341:a0b] {( Tutorials, Eezy )}
- filterUsingPredicate:
Evaluates a given predicate against the mutable ordered sets content and leaves only objects that match.
Example
NSMutableOrderedSet *orderedSet = [[NSMutableOrderedSet alloc]init]; [orderedSet addObjectsFromArray:@[@"Eezy", @"Tutorials"]]; [orderedSet filterUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] 'E'"]]; NSLog(@"%@",orderedSet);
Output
2014-04-12 20:36:19.750 iOS-Tutorial[2366:a0b] {( Eezy )}
Advertisements