Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Priority documentation not matching reality #55

Open
indieSoftware opened this issue Mar 29, 2018 · 4 comments
Open

Priority documentation not matching reality #55

indieSoftware opened this issue Mar 29, 2018 · 4 comments

Comments

@indieSoftware
Copy link

According to the readme the priority can be set with a number like

view.centerXAnchor == view.superview.centerXAnchor + 20 ~ 752

but that doesn't seem to work. The compiler always complains about it with the message Cannot convert value of type 'Int' to expected argument type 'Priority'.

However, using an instance of Priority works:

view.centerXAnchor == view.superview.centerXAnchor + 20 ~ .init(752)

So either the documentation is wrong or there is a bug which doesn't allow to use an Integer directly.

@ZevEisenberg
Copy link
Collaborator

@indieSoftware good catch. This appears to be a documentation bug, although it would be interesting to see if we could support the usage as it is spelled in the docs. However, I think it is probably more idiomatic to use the .high + 2 spelling instead of the literal 752.

@jvisenti
Copy link
Contributor

Looks like there's a priority issue with the ~ operator. This compiles fine:

view.topAnchor == container.topAnchor ~ 1

@ZevEisenberg
Copy link
Collaborator

I don't think it's a priority issue. The priorities on ~ seem reasonable. The given code should be hitting this function:

@discardableResult public func ~ <T, U>(lhs: LayoutExpression<T, U>, rhs: Priority) -> LayoutExpression<T, U> {
    var expr = lhs
    expr.priority = rhs
    return expr
}

So the 752 should be going through Priority's ExpressibleByIntegerLiteral conformance. The fact that it's not is what's confusing to me, since the compiler clearly understands that the type of the right-hand side should be a Priority, and it has a value that it should be able to convert.

@indieSoftware
Copy link
Author

indieSoftware commented Apr 18, 2018

The following doesn't work either (is not mentioned by the documentation, but would be nice to have):

button.widthAnchor >= 44 ~ 990

I have to use it this way:

button.widthAnchor >= 44 ~ Priority(990)

or

button.widthAnchor >= 44 ~ .required - 10

@ZevEisenberg is right, for some reason the ExpressibleByIntegerLiteral doesn't trigger when relied on as operator parameter. When I add the following statement to bypass it and specifying the type explicitly, then button.widthAnchor >= 44 ~ 990 works:

@discardableResult public func ~ (lhs: Int, rhs: Int) -> LayoutExpression<NSLayoutDimension, CGFloat> {
	return LayoutExpression(constant: CGFloat(lhs), priority: Priority(rhs))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants