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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/hex init #26

Merged
merged 3 commits into from Aug 29, 2016
Merged

Fix/hex init #26

merged 3 commits into from Aug 29, 2016

Conversation

zenangst
Copy link
Owner

@zenangst zenangst commented Aug 29, 2016

This PR refactors the static .hex() method into init(hex:_).

Why? Well, to me (and others 馃槑), it makes more sense for it to be an initializer than a static method returning a color based on the hex that you pass it.

So instead of;

let color = UIColor.hex("#ff0")

You鈥檒l do;

let color = UIColor(hex:"#ff0")

The old method is still there in this version but it is marked as deprecated.

@RamonGilabert
Copy link
Contributor

馃崳

@zenangst
Copy link
Owner Author

Migrating current implementations is just a search and replace:

UIColor.hex(
UIColor(hex:


if hex.characters.count == 3 {
for (index, char) in hex.characters.enumerate() {
hex.insert(char, atIndex: hex.startIndex.advancedBy(index * 2))
}
}

return NSColor(
self.init(
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice. Should we move the same hex -> r g b parsing in UIColor, NSColor into a common function?

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.

None yet

4 participants