Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 329 lines (221 sloc) 12.216 kB
cb0e2e8 readme tweaks
Marc Liyanage authored
1 About This Package
2 ==================
3
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
4 Here are some Xcode text macros I use for writing Objective-C code.
5 They speed up my coding a lot, especially the macros for methods.
6
7 Let me know if you wrote useful macros that you would like to add
8 to this collection. The best way is by forking this project on github,
9 adding your macros, and sending me a pull request.
10
11 There is also a cheat sheet generator that lists the macros on an HTML
12 page with their completion prefixes and your keybord shortcuts.
cac6a2b containers (mutable arrays etc.)
Marc Liyanage authored
13 [Here’s an example](http://www.entropy.ch/software/macosx/xcode-macro-cheat-sheet.html)
14 with my particular keyboard shortcuts. You’re more than welcome to
15 spice up that HTML in the XSLT :-)
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
16
17
18 About Xcode’s Text Macros in General
19 ====================================
20
c260464 Readme edits, XCCodeSenseAutoSuggestionStyle tip.
Marc Liyanage authored
21 My guess is that text macros are not well known to many Xcode users. They aren’t
22 easy to find where they are, deep down in submenus of the Edit menu, with no default
23 keyboard shortcuts. I know I didn’t use them a lot, I used
a323cfb Expanded README content, renamed macro file.
Marc Liyanage authored
24 [Objective Development](http://www.obdev.at)’s
25 [Completion Dictionary](http://www.obdev.at/products/completion-dictionary/index.html)
c260464 Readme edits, XCCodeSenseAutoSuggestionStyle tip.
Marc Liyanage authored
26 instead. Personally, I would give the macros their own toplevel menu bar item in Xcode,
27 with a nice space-saving icon like the one
c02c769 More readme editing.
Marc Liyanage authored
28 [BBEdit](http://www.barebones.com/products/bbedit/) uses for its clippings.
a323cfb Expanded README content, renamed macro file.
Marc Liyanage authored
29
c260464 Readme edits, XCCodeSenseAutoSuggestionStyle tip.
Marc Liyanage authored
30 Xcode’s macro system is very powerful. The first step to harnessing that power
cac6a2b containers (mutable arrays etc.)
Marc Liyanage authored
31 for your daily coding is to start using the macros that are already there:
a323cfb Expanded README content, renamed macro file.
Marc Liyanage authored
32
c260464 Readme edits, XCCodeSenseAutoSuggestionStyle tip.
Marc Liyanage authored
33 * Assigning keyboard shortcuts to the most often used ones is *highly*
34 recommended, especially to get one of the coolest macro features,
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
35 cycle lists. Cycle lists link together related macros and let you
cac6a2b containers (mutable arrays etc.)
Marc Liyanage authored
36 quickly flip through them by repeatedly pressing the shortcut. While
37 Xcode switches from variant to variant, it preserves your wrapped
38 selected text (see next item) and replaces just the macro code around
39 it.
40 Cycle lists are useful for variants of similar constructs such as `if ()`
41 statements or method definitions. Until recently I didn’t know about
42 cycle lists. The cheat sheet shows you which macros are grouped together
43 in such a list.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
44 * Another great feature that’s easier to use with keyboard shortcuts is
45 the ability of some macros to wrap selected text. Again this is useful
5f75474 More Readme edits.
Marc Liyanage authored
46 for block statements such as `if ()`, especially in combination with the previous
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
47 feature. Select a bunch of lines, hit the shortcut to wrap them in an
5f75474 More Readme edits.
Marc Liyanage authored
48 `if ()` block, hit the shortcut again to switch to an `if / else` block.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
49 Taken together, this results in a killer feature.
50 * I recommend picking a simple and consistent keyboard shortcut convention
51 across all macros. I use just the Ctrl key with letters. Obviously
52 this only works because I don’t use the emacs text editing bindings,
53 except maybe Ctrl-T once in a while. My recommendations are listed below
5f75474 More Readme edits.
Marc Liyanage authored
54 in the macro list and in the cheat sheet sample. You could also use the
55 number keys with Cmd-Ctrl. Whatever you pick, if you make it something
56 simple and unified, you’ll have an easier time remembering the shortcuts,
57 and only if you remember and use them a lot will you get the full time-saving
58 benefit.
59 * You might use some macros once in a while, but not often enough to justify
b2b7a0d add hint about completion prefix to readme.
Marc Liyanage authored
60 giving them their own shortcut. In those cases it’s a good idea to
5f75474 More Readme edits.
Marc Liyanage authored
61 still memorize their completion shortcut, which is the next best thing.
b2b7a0d add hint about completion prefix to readme.
Marc Liyanage authored
62 To insert the macro, type the completion shortcut and hit the tab key.
9c38457 Move tip to bullet list
Marc Liyanage authored
63 * I like to see the completion suggestions right away in a popup list.
64 I set the “Automatically Suggest” time in the Xcode preferences to “Immediate”
65 and enabled the list with this setting: `defaults write com.apple.Xcode XCCodeSenseAutoSuggestionStyle List`.
a323cfb Expanded README content, renamed macro file.
Marc Liyanage authored
66
4843635 Added IBOutlet property declarations and methods returning BOOL
Marc Liyanage authored
67 The next step is to start writing (and hopefully sharing) your own macros:
a323cfb Expanded README content, renamed macro file.
Marc Liyanage authored
68
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
69 * Xcode’s macro language is fairly complicated, and as far as I know not
70 well-documented, but it is also very powerful because it uses an inheritance
71 system and flexible token replacement features. It’s worth to learn it,
cb0e2e8 readme tweaks
Marc Liyanage authored
72 and you can learn a lot by looking at the built-in `C.xctxtmacro` file.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
73 The built-in macro files are in the Xcode application bundle in
cb0e2e8 readme tweaks
Marc Liyanage authored
74 `Contents/PlugIns/TextMacros.xctxtmacro/Contents/Resources/`.
75 * The Xcode user defaults also influence the macros, specifically the whitespace.
76 These defaults are documented [here](http://developer.apple.com/mac/library/documentation/DeveloperTools/Reference/XcodeUserDefaultRef/100-Xcode_User_Defaults/UserDefaultRef.html#//apple_ref/doc/uid/TP40005535-CH3-SW40).
7864022 readme additions regarding context lists
Marc Liyanage authored
77 * Completion prefixes are more useful when you limit the macros to the
78 source code contexts in which they make sense. You do that by specifying
79 appropriate context include and exclude lists for each macro. To find out
80 what contexts are active at a particular source code location, I use
81 a one-line shell script with the command `echo $XCSourceContext`
82 that I added as an Xcode user script. I place the cursor in the location
83 I’m interested in and run the script, which inserts the list of context
84 identifiers.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
85
c260464 Readme edits, XCCodeSenseAutoSuggestionStyle tip.
Marc Liyanage authored
86
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
87 About the Macros
88 ================
89
a323cfb Expanded README content, renamed macro file.
Marc Liyanage authored
90 With both the built-in macros and the ones in this collection here, play
91 around a bit, with something selected, nothing selected etc. to see what
92 gets wrapped, where the cursor ends up, what placeholders get inserted.
93 If you spend a lot of time in Xcode, you’ll really want to get familiar
94 with text macros.
cb0e2e8 readme tweaks
Marc Liyanage authored
95
956eb5b Adding installation instructions for Xcode 4 to the README.
Jan Weiß authored
96 Installation Xcode 4
97 --------------------
98
99 cd *your-git-repository*
100 ln -s "$PWD/MyMacros-CodeSnippets" ~/Library/Developer/Xcode/UserData/CodeSnippets
101
102 Sadly, you currently can’t collect links/aliases to your code snippets within the `~/Library/Developer/Xcode/UserData/CodeSnippets` directory. Xcode 4 seems to expect a flat directory structure.
103
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
104 Installation
105 ------------
106
107 Put the .xctxtmacro file into your
108
109 "$HOME/Library/Application Support/Developer/Shared/Xcode/Specifications/"
110
111 directory. Then restart Xcode so it picks them up. *Definitely* assign keyboard
cb0e2e8 readme tweaks
Marc Liyanage authored
112 shortcuts :-)
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
113
438b1fc Git clone tip added to readme
Marc Liyanage authored
114 Ideally, you would `git clone` this project directly from GitHub
115 to some location on your system and put a symbolic link to the macro file into
42331c4 Small improvements to the README.
Jan Weiß authored
116 the directory given above.
117
118 As the directory is not there by default, the easiest way to create it is
119
120 `mkdir -p "$HOME/Library/Application Support/Developer/Shared/Xcode/Specifications/"`
121
122 which will recursively create all necessary directories down to that level. Then add a
123 symbolic link to the .xctxtmacro file:
124
125 `ln -s *your-git-repository*/MyMacros.xctxtmacro "$HOME/Library/Application Support/Developer/Shared/Xcode/Specifications/"`
126
127 That way, you can always update to the newest version
438b1fc Git clone tip added to readme
Marc Liyanage authored
128 of the macro collection with a simple `git pull`. If you start your own collection
44b513e last edit for today :)
Marc Liyanage authored
129 of macros, put them into a separate file in the same directory.
438b1fc Git clone tip added to readme
Marc Liyanage authored
130
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
131 Here’s a quick run-down of some of the macros:
132
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
133
134 Strings
135 -------
136
137 ### Objective-C String Literal
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
138
cb0e2e8 readme tweaks
Marc Liyanage authored
139 Inserts `@""`. If something is selected, it puts that between the quotes.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
140 Without selection, moves the cursor between the quotes.
141
142 Recommended shortcut: ⌃\
143
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
144 ### NSString With Format
145
3f1e6bd readme formatting tweak
Marc Liyanage authored
146 Inserts `[NSString stringWithFormat:...]` with a format string and arguments placeholders.
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
147
148 Recommended shortcut: ⌃F
149
cac6a2b containers (mutable arrays etc.)
Marc Liyanage authored
150 Containers
151 -------
152
153 ### NSMutableArray
154
155 Inserts `NSMutableArray *`.
156
157 Recommended shortcut: use completion prefix `nsma`
158
159 ### NSMutableArray array
160
161 Inserts `[NSMutableArray array]`.
162
163 Recommended shortcut: use completion prefix `nsmaa`
164
165 ### NSString With Format
166
167 Inserts `[NSString stringWithFormat:...]` with a format string and arguments placeholders.
168
169 Recommended shortcut: ⌃F
170
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
171
172 NSLog()
173 -------
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
174
cb0e2e8 readme tweaks
Marc Liyanage authored
175 Inserts `NSLog()` calls with zero and one arguments. The two are linked
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
176 in a cycle list.
177
178 Recommended shortcut: ⌃L
179
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
180
181 Control Statements
182 ------------------
183
184 ### Single-Statement if ()
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
185
cb0e2e8 readme tweaks
Marc Liyanage authored
186 Inserts an `if ()` statement without the braces. It’s linked to several
187 other `if ()` statement variants in a cycle list.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
188
318dfdd readme tweaks
Marc Liyanage authored
189 Recommended shortcut: ⌃I
190
84cd64b Added libdispatch macros. Added TODO and FIXME marker macros. Upated …
Marc Liyanage authored
191 Markers
192 -------
193
194 ### TODO Marker
195
196 Inserts a `// TODO:` comment, which will show up in Xcode’s function popup.
197
198 Recommended shortcut: Use completion prefix `todo`;
199
200 ### FIXME Marker
201
202 Inserts a `// FIXME:` comment, which will show up in Xcode’s function popup.
203
204 Recommended shortcut: Use completion prefix `fix`;
205
206 ### TODO Marker
207
208 Inserts a `// !!!:` comment, which will show up in Xcode’s function popup.
209
210 Recommended shortcut: Use completion prefix `fix2`;
211
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
212 Methods
213 -------
214
215 ### Declarations and Definitions
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
216
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
217 Several variants of method declarations and definitions with different return
218 value and parameter combinations. If you assign a keyboard shortcut, it should
219 be assigned to the “Return Value no Parameters” variants of declaration or definition
220 because those define the cycle list.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
221
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
222 The completion prefixes are identical for declaration and definition of each variant,
223 but the macros are context-sensitive. If you use a completion prefix in an implementation
224 context, a definition will be inserted, and if you use the same prefix in an interface
225 context, a declaration will be inserted.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
226
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
227 Recommended shortcut for definition: ⌃M
253359e Add release and nil ivar macro. Change completion prefix for IBAction…
Marc Liyanage authored
228
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
229 Recommended shortcut for declaration: ⌃H
230
231 ### Method Parameter
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
232
cb0e2e8 readme tweaks
Marc Liyanage authored
233 Inserts an `xxxx:(yyy)zzz` sequence to add a parameter to a method
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
234 definition/declaration. Ideal for combination with the method
235 blocks in the previous item.
236
253359e Add release and nil ivar macro. Change completion prefix for IBAction…
Marc Liyanage authored
237 Recommended shortcut: Suggest to use the completion prefix.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
238
84cd64b Added libdispatch macros. Added TODO and FIXME marker macros. Upated …
Marc Liyanage authored
239 ### Bracket Expression
240
241 Inserts a bracket expression. The built-in bracket expression has
242 a trailing space that I don’t like.
243
244 Recommended shortcut: ⌃[
245
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
246 Properties
247 ----------
248
249 ### Declarations
1a59639 Added @property and @synthesize macros.
Marc Liyanage authored
250
42331c4 Small improvements to the README.
Jan Weiß authored
251 Inserts `@property` declarations. If you assign a keyboard shortcut, it should
252 be assigned to the “retain” variant. Cycles through three variants with
1a59639 Added @property and @synthesize macros.
Marc Liyanage authored
253 the `retain`, `assign` and `copy` attributes. The selection ends
254 up in the type and name part. Tip: copy/paste the property’s
255 instance variable declaration and paste it where you want the
256 declaration, select it and invoke the shortcut.
257
253359e Add release and nil ivar macro. Change completion prefix for IBAction…
Marc Liyanage authored
258 Recommended shortcut: ⌃P
1a59639 Added @property and @synthesize macros.
Marc Liyanage authored
259
4236b36 context sensitive method macros (definition/declaration variants for …
Marc Liyanage authored
260 ### Synthesize
1a59639 Added @property and @synthesize macros.
Marc Liyanage authored
261
253359e Add release and nil ivar macro. Change completion prefix for IBAction…
Marc Liyanage authored
262 Inserts `@synthesize` instructions. Cycles through two variants,
1a59639 Added @property and @synthesize macros.
Marc Liyanage authored
263 the second of which uses the `property = ivar` form to assign the
264 property to an ivar with a different name.
265
266 Recommended shortcut: ⌃S
267
253359e Add release and nil ivar macro. Change completion prefix for IBAction…
Marc Liyanage authored
268 ### Release and nil ivar
269
270 Inserts two lines to release and nil an ivar in a dealloc method.
271 The selection is used as ivar name.
272
84cd64b Added libdispatch macros. Added TODO and FIXME marker macros. Upated …
Marc Liyanage authored
273 Recommended shortcut: Use the completion prefix `rel`.
274
275 Grand Central Dispatch
276 ----------------------
277
278 ### dispatch_async() to Global Concurrent Queue
279
280 Inserts a `dispatch_async()` statement with a block literal targeting
281 the global concurrent queue. A selection or the cursor ends up in the block.
f7fd235 Added block literals with 3 variants.
Marc Liyanage authored
282 Cycles through the other dispatch_* variants below.
84cd64b Added libdispatch macros. Added TODO and FIXME marker macros. Upated …
Marc Liyanage authored
283
f7fd235 Added block literals with 3 variants.
Marc Liyanage authored
284 Recommended shortcut: ⌃D or use the completion prefix, `dia`.
84cd64b Added libdispatch macros. Added TODO and FIXME marker macros. Upated …
Marc Liyanage authored
285
286 ### dispatch_async() to Main Queue
287
288 Inserts a `dispatch_async()` statement with a block literal targeting
289 the main queue. A selection or the cursor ends up in the block.
290
291 Recommended shortcut: Use completion prefix `diam`.
292
293 ### dispatch_sync() to Main Queue
294
295 Inserts a `dispatch_sync()` statement with a block literal targeting
296 the main queue. A selection or the cursor ends up in the block.
297
298 Recommended shortcut: Use completion prefix `dis`.
299
f7fd235 Added block literals with 3 variants.
Marc Liyanage authored
300 ### Block Literal
301
302 Inserts a block literal. Cycles through variants with an empty argument
303 list and an argument list for an NSComparator block. A selection or the
304 cursor ends up between the braces.
305
306 Recommended shortcut: Use completion prefix ⌃]
307
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
308
309 About the Cheat Sheet Generator
310 ===============================
311
312 The cheat sheet generator reads the macros in Apple’s C and
313 Objective-C files built in to Xcode. By default it doesn’t
314 read the shortcuts for C++ or the other languages supported
315 by Xcode, because I don’t use those and don’t want them cluttering
316 up the list. If you want them you can enable them in the generator’s
cb0e2e8 readme tweaks
Marc Liyanage authored
317 `read_macro_definitions()` method.
506a756 Generator cleanup, added link to github page, added README.
Marc Liyanage authored
318
6caa97a Readme tweaks.
Marc Liyanage authored
319 It doesn’t skip any of the `.xctxtmacro` files in your personal
320 directory, as it’s likely that you want all of those...
12e3b2e readme tweaks
Marc Liyanage authored
321
322
f5407cd added link to xobjc project, fixes #1.
Marc Liyanage authored
323 Related Projects
324 ================
325
326 Here are some related projects:
12e3b2e readme tweaks
Marc Liyanage authored
327
f5407cd added link to xobjc project, fixes #1.
Marc Liyanage authored
328 * [xobjc - Shortcuts for lazy Objective-C developers](http://github.com/holtwick/xobjc)
Something went wrong with that request. Please try again.