-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathCustomStyleData.mm
More file actions
46 lines (39 loc) · 1.28 KB
/
Copy pathCustomStyleData.mm
File metadata and controls
46 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#import "CustomStyleData.h"
@implementation CustomStyleData
- (BOOL)isEmpty {
return _foregroundColor == nil && _backgroundColor == nil;
}
- (void)mergeFromDict:(NSDictionary *)dict {
id fgVal = dict[@"foregroundColor"];
if (fgVal != nil) {
self.foregroundColor =
[fgVal isKindOfClass:[UIColor class]] ? (UIColor *)fgVal : nil;
}
id bgVal = dict[@"backgroundColor"];
if (bgVal != nil) {
self.backgroundColor =
[bgVal isKindOfClass:[UIColor class]] ? (UIColor *)bgVal : nil;
}
}
- (BOOL)isEqual:(id)object {
if (self == object)
return YES;
if (![object isKindOfClass:[CustomStyleData class]])
return NO;
CustomStyleData *other = (CustomStyleData *)object;
BOOL fgEqual = (_foregroundColor == other.foregroundColor) ||
[_foregroundColor isEqual:other.foregroundColor];
BOOL bgEqual = (_backgroundColor == other.backgroundColor) ||
[_backgroundColor isEqual:other.backgroundColor];
return fgEqual && bgEqual;
}
- (NSUInteger)hash {
return [_foregroundColor hash] ^ [_backgroundColor hash];
}
- (id)copyWithZone:(NSZone *)zone {
CustomStyleData *copy = [[CustomStyleData allocWithZone:zone] init];
copy.foregroundColor = self.foregroundColor;
copy.backgroundColor = self.backgroundColor;
return copy;
}
@end