robb/Cartography

Implicit returns in `layout` blocks

Closed this issue · 7 comments

robb commented

There seems to be an implicit return in layout blocks containing only a single statement.

layout(view, superview) { view, superview in
    view.top == superview.top + 100
}

throws over the compiler whereas

layout(view, superview) { view, superview in
    view.top == superview.top + 100
    return
}

doesn't. I guess the compiler treats the first block as (LayoutProxy, LayoutProxy) -> NSLayoutConstraint, in which case overloading layout should do the trick.

mxcl commented

I went to swift lab about this, it's s compiler bug. Should be fixed!

robb commented

Good to know, thx

Still not fixed in 6.1--wanna update the one-line examples on the readme? <3

robb commented

Sure thing

You can also do this (I prefer):

layout(view, superview) { view, superview in
    _ = view.top == superview.top + 100
}
robb commented

This seems to have been addressed in Xcode 6.3beta1

Cool