objc.snippets 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. snippet @interface
  36. @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject}
  37. {${3}
  38. }
  39. ${4}
  40. @end
  41. # Class Implementation
  42. snippet impl
  43. @implementation ${1:`Filename('', 'someClass')`}
  44. ${2}
  45. @end
  46. snippet @implementation
  47. @implementation ${1:`Filename('', 'someClass')`}
  48. ${2}
  49. @end
  50. # Protocol
  51. snippet pro
  52. @protocol ${1:`Filename('$1Delegate', 'MyProtocol')`} ${2:<NSObject>}
  53. ${3}
  54. @end
  55. snippet @protocol
  56. @protocol ${1:`Filename('$1Delegate', 'MyProtocol')`} ${2:<NSObject>}
  57. ${3}
  58. @end
  59. # init Definition
  60. snippet init
  61. - (id)init
  62. {
  63. if (self = [super init]) {
  64. ${1}
  65. }
  66. return self;
  67. }
  68. # dealloc Definition
  69. snippet dealloc
  70. - (void) dealloc
  71. {
  72. ${1:deallocations}
  73. [super dealloc];
  74. }
  75. snippet su
  76. [super ${1:init}]${2}
  77. snippet ibo
  78. IBOutlet ${1:NSSomeClass} *${2:$1};${3}
  79. # Category
  80. snippet cat
  81. @interface ${1:NSObject} (${2:MyCategory})
  82. @end
  83. @implementation $1 ($2)
  84. ${3}
  85. @end
  86. # Category Interface
  87. snippet cath
  88. @interface ${1:`Filename('$1', 'NSObject')`} (${2:MyCategory})
  89. ${3}
  90. @end
  91. # Method
  92. snippet m
  93. - (${1:id})${2:method}
  94. {
  95. ${3}
  96. }
  97. # Method declaration
  98. snippet md
  99. - (${1:id})${2:method};${3}
  100. # IBAction declaration
  101. snippet ibad
  102. - (IBAction)${1:method}:(${2:id})sender;${3}
  103. # IBAction method
  104. snippet iba
  105. - (IBAction)${1:method}:(${2:id})sender
  106. {
  107. ${3}
  108. }
  109. # awakeFromNib method
  110. snippet wake
  111. - (void)awakeFromNib
  112. {
  113. ${1}
  114. }
  115. # Class Method
  116. snippet M
  117. + (${1:id})${2:method}
  118. {
  119. ${3:return nil;}
  120. }
  121. # Sub-method (Call super)
  122. snippet sm
  123. - (${1:id})${2:method}
  124. {
  125. [super $2];${3}
  126. return self;
  127. }
  128. # Accessor Methods For:
  129. # Object
  130. snippet objacc
  131. - (${1:id})${2:thing}
  132. {
  133. return $2;
  134. }
  135. - (void)set$2:($1)${3:new$2}
  136. {
  137. [$3 retain];
  138. [$2 release];
  139. $2 = $3;
  140. }${4}
  141. # for (object in array)
  142. snippet forin
  143. for (${1:Class} *${2:some$1} in ${3:array}) {
  144. ${4}
  145. }
  146. snippet fore
  147. for (${1:object} in ${2:array}) {
  148. ${3:statements}
  149. }
  150. snippet forarray
  151. unsigned int ${1:object}Count = [${2:array} count];
  152. for (unsigned int index = 0; index < $1Count; index++) {
  153. ${3:id} $1 = [$2 $1AtIndex:index];
  154. ${4}
  155. }
  156. snippet fora
  157. unsigned int ${1:object}Count = [${2:array} count];
  158. for (unsigned int index = 0; index < $1Count; index++) {
  159. ${3:id} $1 = [$2 $1AtIndex:index];
  160. ${4}
  161. }
  162. # Try / Catch Block
  163. snippet @try
  164. @try {
  165. ${1:statements}
  166. }
  167. @catch (NSException * e) {
  168. ${2:handler}
  169. }
  170. @finally {
  171. ${3:statements}
  172. }
  173. snippet @catch
  174. @catch (${1:exception}) {
  175. ${2:handler}
  176. }
  177. snippet @finally
  178. @finally {
  179. ${1:statements}
  180. }
  181. # IBOutlet
  182. # @property (Objective-C 2.0)
  183. snippet prop
  184. @property (${1:retain}) ${2:NSSomeClass} ${3:*$2};${4}
  185. # @synthesize (Objective-C 2.0)
  186. snippet syn
  187. @synthesize ${1:property};${2}
  188. # [[ alloc] init]
  189. snippet alloc
  190. [[${1:foo} alloc] init${2}];${3}
  191. snippet a
  192. [[${1:foo} alloc] init${2}];${3}
  193. # retain
  194. snippet ret
  195. [${1:foo} retain];${2}
  196. # release
  197. snippet rel
  198. [${1:foo} release];
  199. # autorelease
  200. snippet arel
  201. [${1:foo} autorelease];
  202. # autorelease pool
  203. snippet pool
  204. NSAutoreleasePool *${1:pool} = [[NSAutoreleasePool alloc] init];
  205. ${2:/* code */}
  206. [$1 drain];
  207. # Throw an exception
  208. snippet except
  209. NSException *${1:badness};
  210. $1 = [NSException exceptionWithName:@"${2:$1Name}"
  211. reason:@"${3}"
  212. userInfo:nil];
  213. [$1 raise];
  214. snippet prag
  215. #pragma mark ${1:-}
  216. snippet cl
  217. @class ${1:Foo};${2}
  218. snippet color
  219. [[NSColor ${1:blackColor}] set];
  220. # NSArray
  221. snippet array
  222. NSMutableArray *${1:array} = [NSMutable array];${2}
  223. snippet nsa
  224. NSArray ${1}
  225. snippet nsma
  226. NSMutableArray ${1}
  227. snippet aa
  228. NSArray * array;${1}
  229. snippet ma
  230. NSMutableArray * array;${1}
  231. # NSDictionary
  232. snippet dict
  233. NSMutableDictionary *${1:dict} = [NSMutableDictionary dictionary];${2}
  234. snippet nsd
  235. NSDictionary ${1}
  236. snippet nsmd
  237. NSMutableDictionary ${1}
  238. # NSString
  239. snippet nss
  240. NSString ${1}
  241. snippet nsms
  242. NSMutableString ${1}