Re:Building DSLs in Swift
by aaaaaaaaaab on Monday October 15, 2018 @03:57PM
(#18223118)
You can use the regular NSLayoutConstraints.activate() API, or you can set it back to true.
Also, notice that translatesAutoresizingMaskIntoConstraints will only be set on the view which you call `layout` on. I.e. this is bogus:
self.contentView.layout { make in
make.left.equal(self.otherView)
}
But this is “fine”:
self.otherView.layout { make in
make.left.equal(self.contentView)
}
Of course now you’re relying on implementation details of SnapKot/Masonry/whatever.
I personally just use the built-in anchor APIs with a few helpers (e.g. to create constraints to match all 4 edges of two views). In swift you have operator+ for arrays, so NSLayoutConstraints.activate(...) can be pretty succint this way.
Also, notice that translatesAutoresizingMaskIntoConstraints will only be set on the view which you call `layout` on. I.e. this is bogus:
But this is “fine”: Of course now you’re relying on implementation details of SnapKot/Masonry/whatever.I personally just use the built-in anchor APIs with a few helpers (e.g. to create constraints to match all 4 edges of two views). In swift you have operator+ for arrays, so NSLayoutConstraints.activate(...) can be pretty succint this way.