react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #import "Param.h"
  2. @interface Param()
  3. @property (nonatomic, retain) id value;
  4. @property (nonatomic) BOOL consumed;
  5. @end
  6. @implementation Param
  7. + (instancetype)withValue:(id)value {
  8. return [[self.class alloc] initWithValue:value];
  9. }
  10. - (instancetype)initWithValue:(id)value {
  11. self = [super init];
  12. self.value = value;
  13. return self;
  14. }
  15. - (id)get {
  16. if (!self.value) {
  17. @throw [NSException exceptionWithName:@"Param get" reason:@"value does not exists" userInfo:nil];
  18. }
  19. return self.value;
  20. }
  21. - (id)getWithDefaultValue:(id)defaultValue {
  22. if (self.value) {
  23. return self.value;
  24. } else if (defaultValue) {
  25. return defaultValue;
  26. }
  27. return nil;
  28. }
  29. - (void)consume {
  30. self.consumed = true;
  31. }
  32. - (BOOL)hasValue {
  33. return self.value && !self.consumed;
  34. }
  35. @end