robb/Cartography

Remove `constrain` closures

Open

#145 建立於 2015年7月10日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)Swift (7,337 star) (522 fork)batch import
help wantedquestion

描述

As per @smileyborg in #144:

BTW, on the note of significant breaking changes like this, I'd love to also explore what Cartography would look like if it didn't use closures passed to constraint (or layout) and instead added some "NSLayoutAnchor-like" properties of type LayoutProxy to UIView/NSView, which would let you use the custom operators to create constraints without having to pass the view(s) into a closure first.

I've thought about this, we'd basically replace

constrain(view1, view2) {
    view1.width  == view2.width
    view1.height == view2.height
}

with, if I understood you right, something like

view1.car_width  == view2.car_width
view1.car_height == view2.car_height

There's two aspects I dislike about this approach. One is that I believe the car_ prefix makes it harder to read. I'd like Cartography to be as close to "pseudocode" as possible, and prefix takes away from that.
There may be another way to attach the properties, such as a surrounding function or an operator but I'm worried it takes away clarity.

The other thing is that I like that the constrain function forces users to have their constraints grouped in a single place, and also sections off the part of the code in which Cartography's operator overloading applies.

It also provides a place to attach additional information. E.g. I'd like to add __LINE__ and __FILE__ default arguments to constrain to make it easier to find where a specific constraint was created in code (#97).

貢獻者指南