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

Interpolate generic initializer #4

Merged
merged 3 commits into from
May 6, 2016
Merged

Conversation

romanroibu
Copy link
Contributor

Use generic initializer to create Interpolate objects. This way, there is no need to typecast inside the apply block, so the code becomes cleaner.

let colorChange = Interpolate(from: UIColor.whiteColor(), to: UIColor.redColor(), apply: { [weak self] (color) in
    self?.view.backgroundColor = color
})

Also, this guarantees that the type of from parameter is the same as the type of to, so there is no way to write code like this:

let change = Interpolate(from: UIColor.whiteColor(), to: 10.0, apply: { [weak self] (result) in
    // This will cause a fatal error in calculateDiff
})

@marmelroy
Copy link
Owner

Thanks @romanroibu ! Big improvement! Don't know why I didn't think about it...

@marmelroy marmelroy merged commit afb5359 into marmelroy:master May 6, 2016
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

Successfully merging this pull request may close these issues.

2 participants