########################################################################### # TextMate Snippets # ########################################################################### snippet imp "#import (imp)" b #import "${1:`!p snip.rv = re.sub(r'\..*$', '.h', fn)`}" endsnippet snippet Imp "#import <> (Imp)" #import <${1:Cocoa/Cocoa.h}> endsnippet snippet cl "020 Class (objc)" @interface ${1:`!p if len(fn): snip.rv = re.sub(r'\..*$', '', fn) else: snip.rv = "object" `} : ${2:NSObject} { } @end @implementation $1 - (id)init { if((self = [super init])) {$0 } return self; } @end endsnippet snippet array "NSArray (array)" NSMutableArray *${1:array} = [NSMutableArray array]; endsnippet snippet dict "NSDictionary (dict)" NSMutableDictionary *${1:dict} = [NSMutableDictionary dictionary]; endsnippet snippet forarray "for NSArray loop (forarray)" unsigned int ${1:object}Count = [${2:array} count]; for(unsigned int index = 0; index < $1Count; index += 1) { ${3:id} $1 = [$2 objectAtIndex:index]; $0 } endsnippet snippet objacc "Object Accessors (objacc)" - (${1:id})${2:thing} { return $2; } - (void)set${2/./\u$0/}:($1)aValue { $0${1/( \*)?$/(?1:$1: )/}old${2/./\u$0/} = $2; $2 = [aValue retain]; [old${2/./\u$0/} release]; } endsnippet snippet sel "@selector" @selector(${1:method}:) endsnippet snippet cdacc "CoreData Accessors Implementation" - (${1:id})${2:attribute} { [self willAccessValueForKey:@"$2"]; $1 value = [self primitiveValueForKey:@"$2"]; [self didAccessValueForKey:@"$2"]; return value; } - (void)set${2/./\u$0/}:($1)aValue { [self willChangeValueForKey:@"$2"]; [self setPrimitiveValue:aValue forKey:@"$2"]; [self didChangeValueForKey:@"$2"]; } endsnippet snippet delegate "Delegate Responds to Selector" if([${1:[self delegate]} respondsToSelector:@selector(${2:selfDidSomething:})]) [$1 ${3:${2/((^\s*([A-Za-z0-9_]*:)\s*)|(:\s*$)|(:\s*))/(?2:$2self :\:<>)(?4::)(?5: :)/g}}]; endsnippet snippet thread "Detach New NSThread" [NSThread detachNewThreadSelector:@selector(${1:method}:) toTarget:${2:aTarget} withObject:${3:anArgument}] endsnippet snippet ibo "IBOutlet (ibo)" IBOutlet ${1:NSSomeClass} *${2:${1/^[A-Z](?:[A-Z]+|[a-z]+)([A-Z]\w*)/\l$1/}}; endsnippet snippet I "Initialize Implementation (I)" + (void)initialize { [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys: $0@"value", @"key", nil]]; } endsnippet snippet bind "Key:value binding (bind)" bind:@"${1:binding}" toObject:${2:observableController} withKeyPath:@"${3:keyPath}" options:${4:nil} endsnippet snippet arracc "LoD array (arracc)" - (void)addObjectTo${1:Things}:(${2:id})anObject { [${3:${1/./\l$0/}} addObject:anObject]; } - (void)insertObject:($2)anObject in$1AtIndex:(unsigned int)i { [$3 insertObject:anObject atIndex:i]; } - ($2)objectIn$1AtIndex:(unsigned int)i { return [$3 objectAtIndex:i]; } - (unsigned int)indexOfObjectIn$1:($2)anObject { return [$3 indexOfObject:anObject]; } - (void)removeObjectFrom$1AtIndex:(unsigned int)i { [$3 removeObjectAtIndex:i]; } - (unsigned int)countOf$1 { return [$3 count]; } - (NSArray *${1/./\l$0/} { return $3; } - (void)set$1:(NSArray *)new$1 { [$3 setArray:new$1]; } endsnippet snippet arracc "LoD array interface (arracc)" - (void)addObjectTo${1:Things}:(${2:id})anObject; - (void)insertObject:($2)anObject in$1AtIndex:(unsigned int)i; - ($2)objectIn$1AtIndex:(unsigned int)i; - (unsigned int)indexOfObjectIn$1:($2)anObject; - (void)removeObjectFrom$1AtIndex:(unsigned int)i; - (unsigned int)countOf$1; - (NSArray *)${1/./\l$0/}; - (void)set$1:(NSArray *)new$1; endsnippet snippet focus "Lock Focus" [self lockFocus]; $0 [self unlockFocus]; endsnippet snippet pool "NSAutoreleasePool (pool)" NSAutoreleasePool *pool = [NSAutoreleasePool new]; $0 [pool drain]; endsnippet snippet log "NSLog (log) 2" NSLog(@"$1"${1/[^%]*(%)?.*/(?1:, :\);)/}$2${1/[^%]*(%)?.*/(?1:\);)/} endsnippet snippet alert "NSRunAlertPanel (alert)" int choice = NSRunAlertPanel(@"${1:Something important!}", @"${2:Something important just happend, and now I need to ask you, do you want to continue?}", @"${3:Continue}", @"${4:Cancel}", nil); if(choice == NSAlertDefaultReturn) // "$3" { $0; } else if(choice == NSAlertAlternateReturn) // "$4" { } endsnippet snippet format "NSString stringWithFormat (format)" [NSString stringWithFormat:@"$1", $2]$0 endsnippet snippet objacc "Object Accessors Interface (objacc)" - (${1:id})${2:thing}; - (void)set${2/./\u$0/}:($1)aValue; endsnippet snippet prop "Property" @property (${1/^(e)$|.*/(?1:r)/}${1:r}${1/^(?:(r)|(e)|(c)|(a))$|.*/(?1:etain)(?2:adonly)(?3:opy)(?4:ssign)/}) ${2:NSSomeClass}$ *${3:${2/^[A-Z](?:[A-Z]+|[a-z]+)([A-Z]\w*)/\l$1/}}; endsnippet snippet getprefs "Read from defaults (getprefs)" [[NSUserDefaults standardUserDefaults] objectForKey:${1:key}]; endsnippet snippet obs "Register for Notification" [[NSNotificationCenter defaultCenter] addObserver:${1:self} selector:@selector(${3:${2/^([A-Z]{2})?(.+?)(Notification)?$/\l$2/}}:) name:${2:NSWindowDidBecomeMainNotification} object:${4:nil}]; endsnippet snippet responds "Responds to Selector" if ([${1:self} respondsToSelector:@selector(${2:someSelector:})]) { [$1 ${3:${2/((:\s*$)|(:\s*))/:<>(?3: )/g}}]; } endsnippet snippet gsave "Save and Restore Graphics Context (gsave)" [NSGraphicsContext saveGraphicsState]; $0 [NSGraphicsContext restoreGraphicsState]; endsnippet snippet acc "Scalar Accessors (acc)" - (${1:unsigned int})${2:thing} { return ${3:$2}; } - (void)set${2/./\u$0/}:(${1:unsigned int})new${2/./\u$0/} { $3 = new${2/./\u$0/}; } endsnippet snippet acc "Scalar Accessors Interface (acc)" - (${1:unsigned int})${2:thing}; - (void)set${2/./\u$0/}:($1)new${2/./\u$0/}; endsnippet snippet stracc "String Accessors (stracc)" - (NSString *)${1:thing} { return ${2:$1}; } - (void)set${1/.*/\u$0/}:(NSString *)/})${3:a${1/.*/\u$0/}} { $3 = [$3 copy]; [$2 release]; $2 = $3; } endsnippet snippet syn "Synthesize" @synthesize ${1:property}; endsnippet snippet setprefs "Write to defaults (setprefs)" [[NSUserDefaults standardUserDefaults] setObject:${1:object} forKey:${2:key}]; endsnippet # vim:ft=snippets: # #import <...> snippet Imp #import <${1:Cocoa/Cocoa.h}>${2} # #import "..." snippet imp #import "${1:`Filename()`.h}"${2} # @selector(...) snippet sel @selector(${1:method}:)${3} # @"..." string snippet s @"${1}"${2} # Object snippet o ${1:NSObject} *${2:foo} = [${3:$1 alloc}]${4};${5} # NSLog(...) snippet log NSLog(@"${1:%@}"${2});${3} # Class snippet objc @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject} { } @end @implementation $1 ${3} @end # Class Interface snippet int @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject} {${3} } ${4} @end # Class Implementation snippet impl @implementation ${1:`Filename('', 'someClass')`} ${2} @end snippet init - (id)init { [super init]; return self; } snippet ifself if (self = [super init]) { ${1:/* code */} } return self; snippet ibo IBOutlet ${1:NSSomeClass} *${2:$1};${3} # Category snippet cat @interface ${1:NSObject} (${2:Category}) @end @implementation $1 ($2) ${3} @end # Category Interface snippet cath @interface ${1:NSObject} (${2:Category}) ${3} @end # NSArray snippet array NSMutableArray *${1:array} = [NSMutable array];${2} # NSDictionary snippet dict NSMutableDictionary *${1:dict} = [NSMutableDictionary dictionary];${2} # NSBezierPath snippet bez NSBezierPath *${1:path} = [NSBezierPath bezierPath];${2} # Method snippet m - (${1:id})${2:method} { ${3} } # Method declaration snippet md - (${1:id})${2:method};${3} # IBAction declaration snippet ibad - (IBAction)${1:method}:(${2:id})sender;${3} # IBAction method snippet iba - (IBAction)${1:method}:(${2:id})sender { ${3} } # awakeFromNib method snippet wake - (void)awakeFromNib { ${1} } # Class Method snippet M + (${1:id})${2:method} {${3} return nil; } # Sub-method (Call super) snippet sm - (${1:id})${2:method} { [super $2];${3} return self; } # Method: Initialize snippet I + (void) initialize { [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWIthObjectsAndKeys: ${1}@"value", @"key", nil]]; } # Accessor Methods For: # Object snippet objacc - (${1:id})${2:thing} { return $2; } - (void)set$2:($1)${3:new$2} { [$3 retain]; [$2 release]; $2 = $3; }${4} # for (object in array) snippet forin for (${1:Class} *${2:some$1} in ${3:array}) { ${4} } snippet forarray unsigned int ${1:object}Count = [${2:array} count]; for (unsigned int index = 0; index < $1Count; index++) { ${3:id} $1 = [$2 $1AtIndex:index]; ${4} } # IBOutlet # @property (Objective-C 2.0) snippet prop @property (${1:retain}) ${2:NSSomeClass} ${3:*$2};${4} # @synthesize (Objective-C 2.0) snippet syn @synthesize ${1:property};${2} # [[ alloc] init] snippet alloc [[${1:foo} alloc] init${2}];${3} # retain snippet ret [${1:foo} retain];${2} # release snippet rel [${1:foo} release]; ${2:$1 = nil;} # autorelease snippet arel [${1:foo} autorelease]; # autorelease pool snippet pool NSAutoreleasePool *${1:pool} = [[NSAutoreleasePool alloc] init]; ${2:/* code */} [$1 drain]; # Throw an exception snippet except NSException *${1:badness}; $1 = [NSException exceptionWithName:@"${2:$1Name}" reason:@"${3}" userInfo:nil]; [$1 raise]; snippet prag #pragma mark ${1:foo} snippet cl @class ${1:Foo};${2} snippet color [[NSColor ${1:blackColor}] set];