mavilein
mavilein

Reputation: 11668

Is there a convenient shortcut/workflow to insert square brackets to send a message / call method in XCode?

I am new Objective C development and i am having trouble with my workflow to send a message. In order to invoke a method a java i would type the following:

obj
// .. i am thinking about what to do... call a method!
obj.
// autocompletion pops up
obj.someMethod()

The workflow in XCode currently is not so convenient for me. Currently if often looks like this:

obj
// .. i am thinking about what to do... send a message!
obj //damn i need to have the bracket at the beginning
// and jumping to the beginning of the line with cmd+arrow ignores indentation!
[obj // now i need the cursor at the end of the line
[obj someMessage //now i have to insert the bracket myself :-(
[obj someMessage]

This gets even worse if i want to chain messages like [[obj someMessage] someOtherMessage].

I know that the workflow is better if i start with a bracket, but often i don't realize until typing that i need a message instead of a property (and that would not help with chaining either). Are there any shortcuts to make my life easier, e.g. wrap a line with brackets?

I hope i was able to express my problem in an understandable fashion. :-)

Upvotes: 2

Views: 477

Answers (1)

David Rönnqvist
David Rönnqvist

Reputation: 56625

Xcode inserts the opening bracket when you add the closing bracket (| is cursor in my example).

Class|
// I am thinking about what to do... send a message!
Class alloc|
// now lets add the closing bracket
Class alloc]|
// opening bracket is inserted (cursor remains at end)
[Class alloc]|
// now I want to init as well
[Class alloc] init|
// and add closing bracket
[Class alloc] init]|
// opening bracket is inserted (cursor remains at end)
[[Class alloc] init]|
// done. let's just add the semi-colon
[[Class alloc] init];|

Upvotes: 7

Related Questions