Reformatting to have method parameters in a new line
Asked Answered
S

4

5

There are so many settings in the preferences for Code->Style->Objective-C. I'm looking for the right one to reformat this line of code

SCPropertyDefinition *test = [SCPropertyDefinition definitionWithName:@"created_at" title:@"Tweeted At" type:SCPropertyTypeLabel];

to this format

SCPropertyDefinition *test = [SCPropertyDefinition definitionWithName:@"created_at" 
                                                                title:@"Tweeted At" 
                                                                 type:SCPropertyTypeLabel];

(the point is to have the colons indention matching)

I guess the it should be in the Wrapping and Braces Tab, but I havn't found the right setting yet. Thanks for your ideas.

Sensual answered 29/4, 2013 at 22:36 Comment(0)
S
13

The setting you are looking for is Wrapping and Braces | Method call arguments set to Chop down if long with enabled Align by colon. Note that there are separate settings for Method parameters.

Sile answered 30/4, 2013 at 14:12 Comment(3)
It seems like this option was removed from AppCode 2. Or moved, but I can't find it. I wish there was a hotkey to toggle a line between the two formatting forms.Cataldo
No it's still there. You should go to settings->Code Style->Obj-C look for "Method parameters" and change "Do not wrap" to "Wrap always" or "Chop down if long"Philistine
This doesn't work anymore. I can't find any reference to Chop Down if Long in Appcode 3.3. Any alternatives?Crossstitch
G
5

(1000 years later, updated to Xcode 15)

Editor > Structure > Format to Multiple Lines:

Shortcut: Ctl + M

From

ManyParamInit(param1: String, param2: String, param3: String)

To:

ManyParamInit(
    param1: String,
    param2: String,
    param3: String
)
Gallipot answered 6/11, 2023 at 19:27 Comment(0)
T
1

It seems like as of App Code 2017.1 (perhaps earlier too) the align by colon option is not available in Swift. You can still tell App Code to chop a long argument/parameter list:

How to find the chop long line dialog

Textbook answered 11/4, 2017 at 16:6 Comment(0)
A
1

Selecting the whole constructor code and then pressing ^ M (control + M)

Adriaadriaens answered 18/6 at 13:35 Comment(1)
Yes, this is nice to have these daysSensual

© 2022 - 2024 — McMap. All rights reserved.