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

Using a constant #36

Closed
mwhuss opened this issue Nov 4, 2014 · 8 comments
Closed

Using a constant #36

mwhuss opened this issue Nov 4, 2014 · 8 comments

Comments

@mwhuss
Copy link

mwhuss commented Nov 4, 2014

I'm trying to use a constant to specify how much of a margin i want to use.

let margin = 10.0

label.top == label.superview!.top + margin

I can't get this to work no matter how I cast margin. Am I missing something?

@robb
Copy link
Owner

robb commented Nov 5, 2014

What error are you getting?

Have you tried casting to CGFloat?

@mwhuss
Copy link
Author

mwhuss commented Nov 5, 2014

let margin = 10.0
view.top == view.superview!.top + margin`

Results in:

Cannot invoke '==' with an argument list of type '(Edge, $T9)'

view.top == view.superview!.top + CGFloat(margin)

Results in:

Cannot invoke '+' with an argument list of type '(Edge, $T11)'

@robb
Copy link
Owner

robb commented Nov 6, 2014

Hmm, it's not affected by #9, is it?

@mwhuss
Copy link
Author

mwhuss commented Nov 6, 2014

No, it happens in multiple line blocks as well. Let me know if you'd like
an example project.

@robb
Copy link
Owner

robb commented Nov 6, 2014

That would be great

@mwhuss
Copy link
Author

mwhuss commented Nov 6, 2014

@robb
Copy link
Owner

robb commented Nov 13, 2014

Ah, dang, you have to cast to Float, not CGFloat. This works for me

let margin = 20.0 as Float

layout(label) { label in
    label.left == label.superview!.left + margin
    label.right == label.superview!.right - margin
}

(sorry for the late reply)

@mwhuss
Copy link
Author

mwhuss commented Nov 13, 2014

Ah great, thanks!

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