12345678910111213141516171819202122232425262728293031323334353637383940414243 |
-
- #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]) {
- [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
|