Skip to content

Instantly share code, notes, and snippets.

@sadlerjw
Created September 30, 2013 15:57
Show Gist options
  • Save sadlerjw/6765942 to your computer and use it in GitHub Desktop.
Save sadlerjw/6765942 to your computer and use it in GitHub Desktop.
A TextExpander shortcut that generates Objective-C collection accessor methods. I'm amazed that the compiler can't synthesize these for you, since they're ever-so-formulaic, so I made a shortcut to fill them in automatically. This shortcut takes the following variables: Property name, Upper-cased property name (eg, comments and Comments), variab…
#pragma mark - %filltext:name=Upper-cased Property Name% collection accessor methods
// since Cocoa can't synthesize them for us, even though they're trivial boilerplate
// This makes me very bitter.
- (NSArray *)%filltext:name=Property Name% {
return %filltext:name=Variable%;
}
- (void)set%filltext:name=Upper-cased Property Name%:(NSArray *)%filltext:name=Property Name% {
%filltext:name=Variable% = [%filltext:name=Property Name% mutableCopy];
}
- (NSUInteger)countOf%filltext:name=Upper-cased Property Name% {
return %filltext:name=Variable%.count;
}
- (id)objectIn%filltext:name=Upper-cased Property Name%AtIndex:(NSUInteger)index {
return %filltext:name=Variable%[index];
}
- (void)get%filltext:name=Upper-cased Property Name%:(%filltext:name=Type% * __unsafe_unretained *)buffer range:(NSRange)inRange {
[%filltext:name=Variable% getObjects:buffer range:inRange];
}
- (void)insertObject:(%filltext:name=Type%*)object in%filltext:name=Upper-cased Property Name%AtIndex:(NSUInteger)index {
[%filltext:name=Variable% insertObject:object atIndex:index];
}
- (void)removeObjectFrom%filltext:name=Upper-cased Property Name%AtIndex:(NSUInteger)index {
[%filltext:name=Variable% removeObjectAtIndex:index];
}
- (void)replaceObjectIn%filltext:name=Upper-cased Property Name%AtIndex:(NSUInteger)index withObject:(id)object {
[%filltext:name=Variable% replaceObjectAtIndex:index withObject:object];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment