Skip to content

Preserve line breaks as I wrote them #157

@arlomedia

Description

@arlomedia

For the most part, Swiftify has been good about preserving the line breaks as I had them in my code. By comparison, this was a big problem I had with the Kotlin converter in Android Studio, which was eager to remove empty lines that I used to organize and separate blocks of code. But Swiftify has still done this in some cases:

  1. If I have many elements in a conditional, it is sometimes nice to break them into separate lines for readability. For example:

    if (
    (itemName == “documentButton”)
    ||
    (itemName == “recordingButton”)
    ||
    (itemName == “midiButton”)
    (etc)
    ) {
    [self doSomething];
    }

This is changed to:

if (itemName == “documentButton”) || (itemName == “recordingButton”) || (itemName == “midiButton”) (etc) {
    doSomething()
}

Converter example: http://swiftify.me/23yd31/1

  1. Conversely, I sometimes have a series of very short conditionals that I like to put on one line. For example:

    if (width < min_width) { width = min_width }
    if (width < max_width) { width = max_width }
    if (height < min_height) { height = min_height }
    if (height > max_height) { height = max_height }

(Yes, that could use max and min functions; this is just an example.) This is changed to:

if (width < min_width) {
    width = min_width
}
if (width < max_width) {
    width = max_width
}
if (height < min_height) {
    height = min_height
}
if (height > max_height) {
    height = max_height
}

Converter example: http://swiftify.me/mvecpr/2

  1. Some classes have dozens of properties, and I use empty lines to group related properties. These lines were preserved for most of my project, but did a recent converter update change this? The last few files I converted had these empty lines stripped out. Hopefully this was not a side effect of issue 153. For example:

    @Property (nonatomic) CGSize boxSize;
    @Property (nonatomic) CGPoint boxPosition;
    @Property (nonatomic, strong) UIColor *boxColor;

    @Property (nonatomic) CGSize lineSize;
    @Property (nonatomic) CGPoint linePosition;
    @Property (nonatomic, strong) UIColor *lineColor;

This is changed to:

var boxSize = CGSize.zero
var boxPosition = CGPoint.zero
var boxColor: UIColor?
var lineSize = CGSize.zero
var linePosition = CGPoint.zero
var lineColor: UIColor?

Converter example: http://swiftify.me/zyu8zi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions