react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #import "RNNOptions.h"
  2. @implementation RNNOptions
  3. -(instancetype)initWithDict:(NSDictionary *)dict {
  4. self = [super init];
  5. [self mergeWith:dict];
  6. return self;
  7. }
  8. - (void)applyOn:(UIViewController *)viewController defaultOptions:(RNNOptions *)defaultOptions {
  9. [defaultOptions applyOn:viewController];
  10. [self applyOn:viewController];
  11. }
  12. -(void)mergeWith:(NSDictionary *)otherOptions {
  13. for (id key in otherOptions) {
  14. if ([self hasProperty:key]) {
  15. if ([[self valueForKey:key] isKindOfClass:[RNNOptions class]]) {
  16. RNNOptions* options = [self valueForKey:key];
  17. [options mergeWith:[otherOptions objectForKey:key]];
  18. } else {
  19. [self setValue:[otherOptions objectForKey:key] forKey:key];
  20. }
  21. }
  22. }
  23. }
  24. -(void)mergeIfEmptyWith:(NSDictionary *)otherOptions {
  25. for (id key in otherOptions) {
  26. if ([self hasProperty:key]) {
  27. if ([[self valueForKey:key] isKindOfClass:[RNNOptions class]]) {
  28. RNNOptions* options = [self valueForKey:key];
  29. [options mergeIfEmptyWith:[otherOptions objectForKey:key]];
  30. } else if (![self valueForKey:key]) {
  31. [self setValue:[otherOptions objectForKey:key] forKey:key];
  32. }
  33. }
  34. }
  35. }
  36. - (BOOL)hasProperty:(NSString*)propName {
  37. return [self respondsToSelector:NSSelectorFromString(propName)];
  38. }
  39. @end