robb / Cartography

A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:
Other
7.34k stars 525 forks source link

Acknowledge Apple's current AutoLayout syntax in Readme (since iOS 9.0) #259

Open sovata8 opened 7 years ago

sovata8 commented 7 years ago

I think it would be a good idea to acknowledge the fact that, while Apple's original AutoLayout API syntax is indeed very verbose, since iOS9 it can be rewritten using their anchor syntax.

For example this code from the Readme file:

addConstraint(NSLayoutConstraint(
    item: button1,
    attribute: .Right,
    relatedBy: .Equal,
    toItem: button2,
    attribute: .Left,
    multiplier: 1.0,
    constant: -12.0
))

becomes:

button1.rightAnchor.constraint(equalTo: button2.leftAnchor, constant: -12.0)

And indeed this points to the fact that in some cases, Apple's anchor syntax is pretty good (in this specific case, it's shorter than Cartography's).

Of course in many other cases Cartography's syntax is probably still shorter even than Apple's revised syntax. Moreover, if a user targets lower than iOS9, then Cartography offers a solution there.

But I think users should be made aware of this revised Apple syntax, so they can make an informed decision about the best solution for their project.

orta commented 7 years ago

Sure, PRs are welcome.