KeyValue.m 742 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // KeyValue.m
  3. // CommonLibrary
  4. //
  5. // Created by Alexi on 14-7-22.
  6. // Copyright (c) 2014年 Alexi Chen. All rights reserved.
  7. //
  8. #import "KeyValue.h"
  9. @implementation KeyValue
  10. + (instancetype)key:(NSString *)key value:(id)value
  11. {
  12. return [[KeyValue alloc] initWithKey:key value:value];
  13. }
  14. - (instancetype)initWithKey:(NSString *)key value:(id)value
  15. {
  16. return [self initWithKey:key value:value action:nil];
  17. }
  18. - (instancetype)initWithKey:(NSString *)key value:(id)value action:(KeyValueAction)action
  19. {
  20. if (self = [super init])
  21. {
  22. self.key = key;
  23. self.value = value;
  24. self.action = action;
  25. }
  26. return self;
  27. }
  28. - (void)keyValueAction
  29. {
  30. if (_action)
  31. {
  32. _action(self);
  33. }
  34. }
  35. @end