Impove default indentation for array and dictionary literals

Originator:steipete
Number:rdar://25656808 Date Originated:11-Apr-2016 06:39 PM
Status:Open Resolved:
Product:Developer Tools Product Version:7.3
Classification:Enhancement Reproducible:Always
 
This is a duplicate of rdar://25655678

Summary:

When breaking up an array literal definition into multiple lines with Xcode, code formatting automatically aligns items with the opening square bracket “@[“. This can create potentially waste a lot of space on the left side and especially with longer definitions cause extra line breaks (see http://cl.ly/0x3Q1S18230P). This could be avoided by instead just indenting the same way a new scope (content between “{“ abd “}”) would be indented.

Steps to Reproduce:

Paste the following code snippet into Xcode:

[NSLayoutConstraint activateConstraints:@[
    [NSLayoutConstraint constraintWithItem:stateLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0],
    [NSLayoutConstraint constraintWithItem:stateLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:0.5 constant:0.0],
    [NSLayoutConstraint constraintWithItem:passwordField attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0],
]];

Expected Results:

It would be formatted like this.

[NSLayoutConstraint activateConstraints:@[
    [NSLayoutConstraint constraintWithItem:stateLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0],
    [NSLayoutConstraint constraintWithItem:stateLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:0.5 constant:0.0],
    [NSLayoutConstraint constraintWithItem:passwordField attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0],
]];

Actual Results:

Instead it is formatter like this. 

[NSLayoutConstraint activateConstraints:@[
                                          [NSLayoutConstraint constraintWithItem:stateLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0],
                                          [NSLayoutConstraint constraintWithItem:stateLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:0.5 constant:0.0],
                                          [NSLayoutConstraint constraintWithItem:passwordField attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0],
                                          ]];

Note: 

Same holds for dictionary literals.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!