react-native-navigation的迁移库

RNNOptions.m 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. [self setValue:[otherOptions objectForKey:key] forKey:key];
  16. }
  17. }
  18. }
  19. -(void)mergeIfEmptyWith:(NSDictionary *)otherOptions {
  20. for (id key in otherOptions) {
  21. if ([self hasProperty:key]) {
  22. if ([[self valueForKey:key] isKindOfClass:[RNNOptions class]]) {
  23. RNNOptions* options = [self valueForKey:key];
  24. [options mergeIfEmptyWith:[otherOptions objectForKey:key]];
  25. } else if (![self valueForKey:key]) {
  26. [self setValue:[otherOptions objectForKey:key] forKey:key];
  27. }
  28. }
  29. }
  30. }
  31. - (BOOL)hasProperty:(NSString*)propName {
  32. return [self respondsToSelector:NSSelectorFromString(propName)];
  33. }
  34. @end