Skip to content

Code Style #5

Description

@dillidon

Hi,

Do you think it would be easier to write code like this:

// instead of
stackView.direction(.row).justifyContent(.spaceBetween).define { (stackView) in
   stackView.addItem(button1).shrink(1).aspectRatio(imageRatio)
   stackView.addItem(button2).marginLeft(10).shrink(1).aspectRatio(imageRatio)
   stackView.addItem(button3).marginLeft(10).shrink(1).aspectRatio(imageRatio)
   stackView.addItem(button4).marginLeft(10).shrink(1).aspectRatio(imageRatio)
}

// use this
stackView
   .direction(.row)
   .align(content: .center)
   .justify(content: .spaceBetween)
   .space(between: 10)
   
stackView.add(button1, button2, button3...)

// using
func add(_ subviews: UIView...) {
   subviews.forEach(addItem)
}

I do not know of such cases when it would be necessary to set margins between objects in a stack.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions