Closed zackliston closed 9 years ago
i think it's not the best solution to this way. I can suggest to throw an exception instead of an assert. If you are not really sure if the hex string works (maybe through user input or an API from a third party) it's absolutely the wrong thing to return a working color. It would drive me nuts not knowing why a default color would be returned.
An Exception is a far better way, you can catch it and handle the error in your own implementation (maybe a default color) but it's not a problem in the HexColors class in my opinion.
I'm having the same issue, and as a result, I have to stop using both HexColors
and another library that relys on hexcolors. I believe one of my ad provider library contains a built in UIColor category in their complied library, which is also named colorWithHexString
.
have you thought about prefixing your category functions with hx_ ?
yeah i can definitely do that.
prefixing will be in the next major release. breaking the current implementation
Line 33 in HexColor.m
assert(7 == hexString.length || 4 == hexString.length);
This crashes the app if the hexString is not the right length. I'd be nice if it just provided a default color instead of crashing. My solution:
It's not perfect, but I think providing a wrong color is a much better experience than crashing the app. Also, I think error handling belongs inside that library rather than outside of it.
Thanks