Collection Accessors
NSMutableArray & NSSet
The settings in this panel are triggered when you choose to generate accessors for NSMutableArray or NSSet via the Accessorizer toolbar items or via actions from the Action Menu or Action Panel.
NSMutableArray “Ordered Collection”
NSSet
“Unordered Collection”
Action Menu
Action Panel
NOTE: If you try to generate ordered collection accessors on an NSSet (unordered), you’ll get zero results. Likewise, if you try to generate unordered collection accessors on an NSMutableArray, you’ll get zero results.
You can set return and argument types here for NSMutableArray ordered collection accessors (also known as “indexed accessors”. Accessorizer tries to handle plural and singular forms of your collection, but be careful to check for the singular spelling of your arguments.
As with NSMutableArray collections, it’s easy to generate the NSSet code from the Action Menu. The action will honor your settings.
The NSSet unordered collection accessor options:
Let’s say you have an NSMutableSet *albums;
If you invoke your Accessorizer Action Panel service via shift-option-cmd-0 )shift option command zero) on the declaration, then open the Action Panel via the global hotkey shift-ctrl-cmd-0 (shift control command zero), you’ll generate the following results (both the declaration and the implementation methods)
Accessorizer 3 brought new actions to the Action Menu and Action Panel for Core Data accessors and Core Data To-Many relationships. See the next section.
- (NSUInteger)countOfAlbums;
- (NSEnumerator *)enumeratorOfAlbums;
- (id)memberOfAlbums:(Album *)anAlbum;
- (void)addAlbumsObject:(Album *)anAlbum;
- (void)addAlbums:(NSSet *)manyObjects;
- (void)removeAlbumsObject:(Album *)anAlbum;
- (void)removeAlbums:(NSSet *)manyObjects;
- (void)intersectAlbums:(NSSet *)otherObjects;
- (NSUInteger)countOfAlbums {
return [_albums count];
}
- (NSEnumerator *)enumeratorOfAlbums {
return [_albums objectEnumerator];
}
- (id)memberOfAlbums:(Album *)anAlbum {
return [_albums member:anAlbum];
}
- (void)addAlbumsObject:(Album *)anAlbum {
[_albums addObject:anAlbum];
}
- (void)addAlbums:(NSSet *)manyObjects {
[_albums unionSet:manyObjects];
}
- (void)removeAlbumsObject:(Album *)anAlbum {
[_albums removeObject:anAlbum];
}
- (void)removeAlbums:(NSSet *)manyObjects {
[_albums minusSet:manyObjects];
}
- (void)intersectAlbums:(NSSet *)otherObjects {
[_albums intersectSet:otherObjects];
}
- (NSUInteger)countOfAlbums;
- (NSEnumerator *)enumeratorOfAlbums;
- (id)memberOfAlbums:(Album *)anAlbum;
- (void)addAlbumsObject:(Album *)anAlbum;
- (void)addAlbums:(NSSet *)manyObjects;
- (void)removeAlbumsObject:(Album *)anAlbum;
- (void)removeAlbums:(NSSet *)manyObjects;
- (NSMutableSet *)primitiveAlbums;
- (void)setPrimitiveAlbums:(NSMutableSet *)anAlbumSet;
- (void)intersectAlbums:(NSSet *)otherObjects;
- (NSUInteger)countOfAlbums {
return [_albums count];
}
- (NSEnumerator *)enumeratorOfAlbums {
return [_albums objectEnumerator];
}
- (id)memberOfAlbums:(Album *)anAlbum {
return [_albums member:anAlbum];
}
- (void)addAlbumsObject:(Album *)anAlbum {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&anAlbum count:1];
[self willChangeValueForKey:@"albums"
withSetMutation:NSKeyValueUnionSetMutation
usingObjects:changedObjects];
[[self primitiveAlbums] addObject:anAlbum];
[self didChangeValueForKey:@"albums"
withSetMutation:NSKeyValueUnionSetMutation
usingObjects:changedObjects];
[changedObjects release];
}
- (void)addAlbums:(NSSet *)manyObjects {
[self willChangeValueForKey:@"albums"
withSetMutation:NSKeyValueUnionSetMutation
usingObjects:manyObjects];
[[self primitiveAlbums] unionSet:manyObjects];
[self didChangeValueForKey:@"albums"
withSetMutation:NSKeyValueUnionSetMutation
usingObjects:manyObjects];
}
- (void)removeAlbumsObject:(Album *)anAlbum {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&anAlbum count:1];
[self willChangeValueForKey:@"albums"
withSetMutation:NSKeyValueMinusSetMutation
usingObjects:changedObjects];
[[self primitiveAlbums] removeObject:anAlbum];
[self didChangeValueForKey:@"albums"
withSetMutation:NSKeyValueMinusSetMutation
usingObjects:changedObjects];
[changedObjects release];
}
- (void)removeAlbums:(NSSet *)manyObjects {
[self willChangeValueForKey:@"albums"
withSetMutation:NSKeyValueMinusSetMutation
usingObjects:manyObjects];
[[self primitiveAlbums] minusSet:manyObjects];
[self didChangeValueForKey:@"albums"
withSetMutation:NSKeyValueMinusSetMutation
usingObjects:manyObjects];
}
- (void)intersectAlbums:(NSSet *)otherObjects {
[_albums intersectSet:otherObjects];
}
With these settings, you’ll get the following results.