Please tell me how to create this Live Template

I want to create a live template for dispatch_async (& sync):

So I created a template, "dasync":

dispatch_async( $QUEUE$, ^{
   $END$
});


And since, at least half the time, the queue is the main queue I want to set up a default for $QUEUE$ of 'dispatch_get_main_queue()'. And that's the sticking point. Putting that in as the default I end up with nothing for $QUEUE$ when the template is interpolated into the file.

I see there are all kind of "expression" types for variables but none of them make any particular sense nor did looking at other templates point me in the right direction.

Can anyone help me write this template?

Kind regards,

Matt

AppCode 1.6 EAP OC-120.38

3 comments
Comment actions Permalink

Matt,

for this, you need to enclose default variable for $QUEUE$ in quotes:
Screen Shot 2012-07-13 at 09.25.55 .png

Don't forget to specify context to 'Objective-C: Statement'.
Here is the help reference for the live templates: http://www.jetbrains.com/phpstorm/webhelp/edit-template-variables-dialog.html

I suggest also watching http://youtrack.jetbrains.com/issue/OC-4623, as it appears that completion doesn't behave well in the case.

0
Comment actions Permalink

Thanks Anton, quotes fixed it.

I guess the "completeSmart" business is about what help you get if you are replacing the default value?

Kind regards,

Matt

0
Comment actions Permalink

Yep, it opens the completion popup automatically.
But you can simply leave 'expression' blank and will be able to invoke smart compltion manually.

0

Please sign in to leave a comment.