metova / ThunderCats

ThunderCats is a lightweight collection of utility extensions added to existing Foundation & UIKit classes.
https://metova.com
MIT License
19 stars 4 forks source link

Add `tc_isValidHexString:` #19

Closed nhgrif closed 8 years ago

nhgrif commented 8 years ago

As we are updating tc_colorWithHexString: to throw an invalid argument exception if an invalid string is passed in, we should provide users with an easy way to pre-check their string to determine if it is valid for converting to a UIColor using tc_colorWithHexString:.

We should add a class method to UIColor called tc_isValidHexColorString: which takes an NSString argument and returns a BOOL. If the string would throw an exception from tc_colorWithHexString:, then tc_isValidHexColorString: should return NO. If the string would correctly generate a UIColor out of tc_colorWithHexString:, then tc_isValidHexColorString: should return YES.

When working on this method, please keep an eye out for duplicated logic between the two aforementioned methods and refactor out anything that can be.