Rightpoint / Anchorage

A collection of operators and utilities that simplify iOS layout code.
MIT License
627 stars 46 forks source link

Multi-binding syntax #63

Open ZevEisenberg opened 5 years ago

ZevEisenberg commented 5 years ago

Not sure if that's the right term for it, but this idea is inspired by SnapKit, which can do this:

someView.snp.makeConstraints { 
    innerView.width.centerX.top.equalToSuperview()
}

I was thinking that an Anchorage-like way to do that would be something more like this:

innerView.anchors([.width, .centerX, .top]) == otherView

As a convenience, we could also supply a constant that means "the superview of the view to the left of the ==:

innerView.anchors([.width, .centerX, .top]) == Anchorage.Superview() // name TBD

Question: would this work with operators that we use to inset/offset things? I think probably not, just to simplify things. We already provide verticalAnchors, horizontalAnchors, edgeAnchors, and centerAnchors for cases where you would want to pin common combinations with an inset/offset. So, I think this should be a compilation error:

innerView.anchors([.width, .centerX, .top]) == otherView + 10