No Description

AWSMTLModel.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // MTLModel.h
  3. // Mantle
  4. //
  5. // Created by Justin Spahr-Summers on 2012-09-11.
  6. // Copyright (c) 2012 GitHub. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. // An abstract base class for model objects, using reflection to provide
  10. // sensible default behaviors.
  11. //
  12. // The default implementations of <NSCopying>, -hash, and -isEqual: make use of
  13. // the +propertyKeys method.
  14. @interface AWSMTLModel : NSObject <NSCopying>
  15. // Returns a new instance of the receiver initialized using
  16. // -initWithDictionary:error:.
  17. + (instancetype)modelWithDictionary:(NSDictionary *)dictionaryValue error:(NSError **)error;
  18. // Initializes the receiver with default values.
  19. //
  20. // This is the designated initializer for this class.
  21. - (instancetype)init;
  22. // Initializes the receiver using key-value coding, setting the keys and values
  23. // in the given dictionary.
  24. //
  25. // Subclass implementations may override this method, calling the super
  26. // implementation, in order to perform further processing and initialization
  27. // after deserialization.
  28. //
  29. // dictionaryValue - Property keys and values to set on the receiver. Any NSNull
  30. // values will be converted to nil before being used. KVC
  31. // validation methods will automatically be invoked for all of
  32. // the properties given. If nil, this method is equivalent to
  33. // -init.
  34. // error - If not NULL, this may be set to any error that occurs
  35. // (like a KVC validation error).
  36. //
  37. // Returns an initialized model object, or nil if validation failed.
  38. - (instancetype)initWithDictionary:(NSDictionary *)dictionaryValue error:(NSError **)error;
  39. // Returns the keys for all @property declarations, except for `readonly`
  40. // properties without ivars, or properties on MTLModel itself.
  41. + (NSSet *)propertyKeys;
  42. // A dictionary representing the properties of the receiver.
  43. //
  44. // The default implementation combines the values corresponding to all
  45. // +propertyKeys into a dictionary, with any nil values represented by NSNull.
  46. //
  47. // This property must never be nil.
  48. @property (nonatomic, copy, readonly) NSDictionary *dictionaryValue;
  49. // Merges the value of the given key on the receiver with the value of the same
  50. // key from the given model object, giving precedence to the other model object.
  51. //
  52. // By default, this method looks for a `-merge<Key>FromModel:` method on the
  53. // receiver, and invokes it if found. If not found, and `model` is not nil, the
  54. // value for the given key is taken from `model`.
  55. - (void)mergeValueForKey:(NSString *)key fromModel:(AWSMTLModel *)model;
  56. // Merges the values of the given model object into the receiver, using
  57. // -mergeValueForKey:fromModel: for each key in +propertyKeys.
  58. //
  59. // `model` must be an instance of the receiver's class or a subclass thereof.
  60. - (void)mergeValuesForKeysFromModel:(AWSMTLModel *)model;
  61. // Compares the receiver with another object for equality.
  62. //
  63. // The default implementation is equivalent to comparing both models'
  64. // -dictionaryValue.
  65. //
  66. // Note that this may lead to infinite loops if the receiver holds a circular
  67. // reference to another MTLModel and both use the default behavior.
  68. // It is recommended to override -isEqual: in this scenario.
  69. - (BOOL)isEqual:(id)object;
  70. // A string that describes the contents of the receiver.
  71. //
  72. // The default implementation is based on the receiver's class and its
  73. // -dictionaryValue.
  74. //
  75. // Note that this may lead to infinite loops if the receiver holds a circular
  76. // reference to another MTLModel and both use the default behavior.
  77. // It is recommended to override -description in this scenario.
  78. - (NSString *)description;
  79. @end
  80. // Implements validation logic for MTLModel.
  81. @interface AWSMTLModel (Validation)
  82. // Validates the model.
  83. //
  84. // The default implementation simply invokes -validateValue:forKey:error: with
  85. // all +propertyKeys and their current value. If -validateValue:forKey:error:
  86. // returns a new value, the property is set to that new value.
  87. //
  88. // error - If not NULL, this may be set to any error that occurs during
  89. // validation
  90. //
  91. // Returns YES if the model is valid, or NO if the validation failed.
  92. - (BOOL)validate:(NSError **)error;
  93. @end
  94. @interface AWSMTLModel (Unavailable)
  95. + (instancetype)modelWithDictionary:(NSDictionary *)dictionaryValue __attribute__((deprecated("Replaced by +modelWithDictionary:error:")));
  96. - (instancetype)initWithDictionary:(NSDictionary *)dictionaryValue __attribute__((deprecated("Replaced by -initWithDictionary:error:")));
  97. + (instancetype)modelWithExternalRepresentation:(NSDictionary *)externalRepresentation __attribute__((deprecated("Replaced by -[MTLJSONAdapter initWithJSONDictionary:modelClass:]")));
  98. - (instancetype)initWithExternalRepresentation:(NSDictionary *)externalRepresentation __attribute__((deprecated("Replaced by -[MTLJSONAdapter initWithJSONDictionary:modelClass:]")));
  99. @property (nonatomic, copy, readonly) NSDictionary *externalRepresentation __attribute__((deprecated("Replaced by MTLJSONAdapter.JSONDictionary")));
  100. + (NSDictionary *)externalRepresentationKeyPathsByPropertyKey __attribute__((deprecated("Replaced by +JSONKeyPathsByPropertyKey in <MTLJSONSerializing>")));
  101. + (NSValueTransformer *)transformerForKey:(NSString *)key __attribute__((deprecated("Replaced by +JSONTransformerForKey: in <MTLJSONSerializing>")));
  102. + (NSDictionary *)migrateExternalRepresentation:(NSDictionary *)externalRepresentation fromVersion:(NSUInteger)fromVersion __attribute__((deprecated("Replaced by -decodeValueForKey:withCoder:modelVersion:")));
  103. @end