rootstrap / ios-base

Boilerplate for new iOS projects using Swift 5. Provides a handful of functionalities.
https://rootstrap.com/
MIT License
256 stars 63 forks source link

Add SnapKit as DSL for constraints #184

Closed pMalvasio closed 2 years ago

pMalvasio commented 2 years ago

What about using SnapKit for writing constraints and placing views? I think this DSL improves a lot the tedious task of writing constraints by code (speed and readability).

Things like (from first PR moving from storyboards to code):

extension UIView {
...
  NSLayoutConstraint.activate([
    leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: leadingMargin),
    trailingAnchor.constraint(
      equalTo: view.trailingAnchor,
      constant: -trailingMargin
    )
  ])
...
}

Could be:

currentView.snp.makeConstraints {
  $0.leading.equalTo(view.snp.leading).offset(...)
  $0.trailing.equalTo(view.snp.trailing).offset(...)
}

Applying this change now implies no rewriting if the migration from storyboards to code continues. We'll be writing this from the begging creating the foundations for future UI.

germanStabile commented 2 years ago

As discussed with the team, the approach to be taken is to add our custom helpers progressively as we refactor out storyboards.