123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
-
- #import "RNNOptions.h"
-
- @implementation RNNOptions
-
- -(instancetype)initWithDict:(NSDictionary *)dict {
- self = [super init];
- [self mergeWith:dict];
- return self;
- }
-
- - (void)applyOn:(UIViewController *)viewController defaultOptions:(RNNOptions *)defaultOptions {
- [defaultOptions applyOn:viewController];
- [self applyOn:viewController];
- }
-
- -(void)mergeWith:(NSDictionary *)otherOptions {
- for (id key in otherOptions) {
- if ([self hasProperty:key]) {
- if ([[self valueForKey:key] isKindOfClass:[RNNOptions class]]) {
- RNNOptions* options = [self valueForKey:key];
- [options mergeWith:[otherOptions objectForKey:key]];
- } else {
- [self setValue:[otherOptions objectForKey:key] forKey:key];
- }
- }
- }
- }
-
- -(void)mergeIfEmptyWith:(NSDictionary *)otherOptions {
- for (id key in otherOptions) {
- if ([self hasProperty:key]) {
- if ([[self valueForKey:key] isKindOfClass:[RNNOptions class]]) {
- RNNOptions* options = [self valueForKey:key];
- [options mergeIfEmptyWith:[otherOptions objectForKey:key]];
- } else if (![self valueForKey:key]) {
- [self setValue:[otherOptions objectForKey:key] forKey:key];
- }
- }
- }
- }
-
- - (BOOL)hasProperty:(NSString*)propName {
- return [self respondsToSelector:NSSelectorFromString(propName)];
- }
-
- @end
|