objc.snippets 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. # #import <...>
  2. snippet Imp
  3. #import <${1:Cocoa/Cocoa.h}>${2}
  4. # #import "..."
  5. snippet imp
  6. #import "${1:`Filename()`.h}"${2}
  7. # @selector(...)
  8. snippet sel
  9. @selector(${1:method}:)${3}
  10. # @"..." string
  11. snippet s
  12. @"${1}"${2}
  13. # Object
  14. snippet o
  15. ${1:NSObject} *${2:foo} = [${3:$1 alloc}]${4};${5}
  16. # NSLog(...)
  17. snippet log
  18. NSLog(@"${1:%@}"${2});${3}
  19. # Class
  20. snippet objc
  21. @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject}
  22. {
  23. }
  24. @end
  25. @implementation $1
  26. ${3}
  27. @end
  28. # Class Interface
  29. snippet int
  30. @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject}
  31. {${3}
  32. }
  33. ${4}
  34. @end
  35. # Class Implementation
  36. snippet impl
  37. @implementation ${1:`Filename('', 'someClass')`}
  38. ${2}
  39. @end
  40. snippet init
  41. - (id)init
  42. {
  43. [super init];
  44. return self;
  45. }
  46. snippet ifself
  47. if (self = [super init]) {
  48. ${1:/* code */}
  49. }
  50. return self;
  51. snippet ibo
  52. IBOutlet ${1:NSSomeClass} *${2:$1};${3}
  53. # Category
  54. snippet cat
  55. @interface ${1:NSObject} (${2:Category})
  56. @end
  57. @implementation $1 ($2)
  58. ${3}
  59. @end
  60. # Category Interface
  61. snippet cath
  62. @interface ${1:NSObject} (${2:Category})
  63. ${3}
  64. @end
  65. # NSArray
  66. snippet array
  67. NSMutableArray *${1:array} = [NSMutable array];${2}
  68. # NSDictionary
  69. snippet dict
  70. NSMutableDictionary *${1:dict} = [NSMutableDictionary dictionary];${2}
  71. # NSBezierPath
  72. snippet bez
  73. NSBezierPath *${1:path} = [NSBezierPath bezierPath];${2}
  74. # Method
  75. snippet m
  76. - (${1:id})${2:method}
  77. {
  78. ${3}
  79. }
  80. # Method declaration
  81. snippet md
  82. - (${1:id})${2:method};${3}
  83. # IBAction declaration
  84. snippet ibad
  85. - (IBAction)${1:method}:(${2:id})sender;${3}
  86. # IBAction method
  87. snippet iba
  88. - (IBAction)${1:method}:(${2:id})sender
  89. {
  90. ${3}
  91. }
  92. # awakeFromNib method
  93. snippet wake
  94. - (void)awakeFromNib
  95. {
  96. ${1}
  97. }
  98. # Class Method
  99. snippet M
  100. + (${1:id})${2:method}
  101. {${3}
  102. return nil;
  103. }
  104. # Sub-method (Call super)
  105. snippet sm
  106. - (${1:id})${2:method}
  107. {
  108. [super $2];${3}
  109. return self;
  110. }
  111. # Method: Initialize
  112. snippet I
  113. + (void) initialize
  114. {
  115. [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWIthObjectsAndKeys:
  116. ${1}@"value", @"key",
  117. nil]];
  118. }
  119. # Accessor Methods For:
  120. # Object
  121. snippet objacc
  122. - (${1:id})${2:thing}
  123. {
  124. return $2;
  125. }
  126. - (void)set$2:($1)${3:new$2}
  127. {
  128. [$3 retain];
  129. [$2 release];
  130. $2 = $3;
  131. }${4}
  132. # for (object in array)
  133. snippet forin
  134. for (${1:Class} *${2:some$1} in ${3:array}) {
  135. ${4}
  136. }
  137. snippet forarray
  138. unsigned int ${1:object}Count = [${2:array} count];
  139. for (unsigned int index = 0; index < $1Count; index++) {
  140. ${3:id} $1 = [$2 $1AtIndex:index];
  141. ${4}
  142. }
  143. # IBOutlet
  144. # @property (Objective-C 2.0)
  145. snippet prop
  146. @property (${1:retain}) ${2:NSSomeClass} ${3:*$2};${4}
  147. # @synthesize (Objective-C 2.0)
  148. snippet syn
  149. @synthesize ${1:property};${2}
  150. # [[ alloc] init]
  151. snippet alloc
  152. [[${1:foo} alloc] init${2}];${3}
  153. # retain
  154. snippet ret
  155. [${1:foo} retain];${2}
  156. # release
  157. snippet rel
  158. [${1:foo} release];
  159. ${2:$1 = nil;}
  160. # autorelease
  161. snippet arel
  162. [${1:foo} autorelease];
  163. # autorelease pool
  164. snippet pool
  165. NSAutoreleasePool *${1:pool} = [[NSAutoreleasePool alloc] init];
  166. ${2:/* code */}
  167. [$1 drain];
  168. # Throw an exception
  169. snippet except
  170. NSException *${1:badness};
  171. $1 = [NSException exceptionWithName:@"${2:$1Name}"
  172. reason:@"${3}"
  173. userInfo:nil];
  174. [$1 raise];
  175. snippet prag
  176. #pragma mark ${1:foo}
  177. snippet cl
  178. @class ${1:Foo};${2}
  179. snippet color
  180. [[NSColor ${1:blackColor}] set];