Repository: airbnb/lottie-ios
File: lottie-ios/Classes/Extensions/UIColor+Expanded.m (Objective-C)

Code before:
  
	CGFloat r,g,b,a;
	if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
  
	return [self LOT_colorByDarkeningToRed:r green:g blue:b alpha:1.0f];
}

#pragma mark String utilities

- (NSString *)LOT_stringFromColor {
	NSAssert(self.canProvideRGBComponents, @"Must be an RGB color to use -LOT_stringFromColor");
	NSString *result;
	switch (self.colorSpaceModel) {
		case kCGColorSpaceModelRGB:
			result = [NSString stringWithFormat:@"{%0.3f, %0.3f, %0.3f, %0.3f}", self.red, self.green, self.blue, self.alpha];
			break;
		case kCGColorSpaceModelMonochrome:
			result = [NSString stringWithFormat:@"{%0.3f, %0.3f}", self.white, self.alpha];
			break;
        case kCGColorSpaceModelLab:
        case kCGColorSpaceModelCMYK:
        case kCGColorSpaceModelDeviceN:
        case kCGColorSpaceModelIndexed:
        case kCGColorSpaceModelPattern:
        case kCGColorSpaceModelUnknown:
		default:
			result = nil;
	}
	return result;
}

- (NSString *)LOT_hexStringValue {
	return [NSString stringWithFormat:@"%0.6X", (unsigned int)self.rgbHex];
}

+ (UIColor *)LOT_colorWithString:(NSString *)stringToConvert {
	NSScanner *scanner = [NSScanner scannerWithString:stringToConvert];
	if (![scanner scanString:@"{" intoString:NULL]) return nil;
	const NSUInteger kMaxComponents = 4;
	float c[kMaxComponents];
	NSUInteger i = 0;
	if (![scanner scanFloat:&c[i++]]) return nil;
	while (1) {
		if ([scanner scanString:@"}" intoString:NULL]) break;
		if (i >= kMaxComponents) return nil;
		if ([scanner scanString:@"," intoString:NULL]) {
			if (![scanner scanFloat:&c[i++]]) return nil;
		} else {
			// either we're at the end of there's an unexpected character here
			// both cases are error conditions
			return nil;

Review comment (suggestion):
Just curious - what is the advantage of including all the enum cases, but leaving the `default` case? I would think that if you wanted to be explicit about the cases, then you should remove the default case. Or leave the default case, and don't both enumerating the unneeded cases.

Code after:
	CGFloat r,g,b,a;
	if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
  
	return [self LOT_colorByDarkeningToRed:r green:g blue:b alpha:1.0f];
}

#pragma mark String utilities

- (NSString *)LOT_stringFromColor {
	NSAssert(self.canProvideRGBComponents, @"Must be an RGB color to use -LOT_stringFromColor");
	NSString *result;
	switch (self.colorSpaceModel) {
		case kCGColorSpaceModelRGB:
			result = [NSString stringWithFormat:@"{%0.3f, %0.3f, %0.3f, %0.3f}", self.red, self.green, self.blue, self.alpha];
			break;
		case kCGColorSpaceModelMonochrome:
			result = [NSString stringWithFormat:@"{%0.3f, %0.3f}", self.white, self.alpha];
			break;
 		case kCGColorSpaceModelLab:
 		case kCGColorSpaceModelCMYK:
 		case kCGColorSpaceModelDeviceN:
 		case kCGColorSpaceModelIndexed:
 		case kCGColorSpaceModelPattern:
 		case kCGColorSpaceModelUnknown:
			result = nil;
	}
	return result;
}

- (NSString *)LOT_hexStringValue {
	return [NSString stringWithFormat:@"%0.6X", (unsigned int)self.rgbHex];
}

+ (UIColor *)LOT_colorWithString:(NSString *)stringToConvert {
	NSScanner *scanner = [NSScanner scannerWithString:stringToConvert];
	if (![scanner scanString:@"{" intoString:NULL]) return nil;
	const NSUInteger kMaxComponents = 4;
	float c[kMaxComponents];
	NSUInteger i = 0;
	if (![scanner scanFloat:&c[i++]]) return nil;
	while (1) {
		if ([scanner scanString:@"}" intoString:NULL]) break;
		if (i >= kMaxComponents) return nil;
		if ([scanner scanString:@"," intoString:NULL]) {
			if (![scanner scanFloat:&c[i++]]) return nil;
		} else {
			// either we're at the end of there's an unexpected character here
			// both cases are error conditions
			return nil;
		}
	}