Skip to content

Commit

Permalink
Merge pull request #2 from Wasappli/improvments/nullability
Browse files Browse the repository at this point in the history
Added nullability to get swift compatibility
  • Loading branch information
ipodishima committed Aug 30, 2017
2 parents e1c0895 + 37ae43e commit b7e3a78
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 166 deletions.
2 changes: 1 addition & 1 deletion Files/NSMutableDictionary+WASubDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

@interface NSMutableDictionary (WASubDictionary)

- (void)wa_setObject:(id)value byCreatingDictionariesForKeyPath:(NSString *)keyPath;
- (void)wa_setObject:(_Nonnull id)value byCreatingDictionariesForKeyPath:(NSString *_Nonnull)keyPath;

@end
2 changes: 1 addition & 1 deletion Files/NSObject+WASetValueIfChanged.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

@interface NSObject (WASetValueIfChanged)

- (void)wa_setValueIfChanged:(id)value forKey:(NSString *)key;
- (void)wa_setValueIfChanged:(_Nonnull id)value forKey:(NSString *_Nonnull)key;

@end
2 changes: 1 addition & 1 deletion Files/WABlockMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

@import Foundation;

typedef id (^WAMappingBlock)(id value);
typedef _Nonnull id (^WAMappingBlock)(_Nonnull id value);
8 changes: 4 additions & 4 deletions Files/WACoreDataStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
@interface WACoreDataStore : NSObject <WAStoreProtocol>

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
+ (instancetype _Nonnull)new NS_UNAVAILABLE;

/**
* Create a new store with a managed object context
Expand All @@ -27,8 +27,8 @@
*
* @return an instance of a CoreData store
*/
- (instancetype)initWithManagedObjectContext:(NSManagedObjectContext *)managedObjectContext NS_DESIGNATED_INITIALIZER;
- (instancetype _Nonnull)initWithManagedObjectContext:(NSManagedObjectContext *_Nonnull)managedObjectContext NS_DESIGNATED_INITIALIZER;

@property (nonatomic, readonly, strong) NSManagedObjectContext *context;
@property (nonatomic, readonly, strong) NSManagedObjectContext *_Nonnull context;

@end
30 changes: 15 additions & 15 deletions Files/WAEntityMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@
*/
@interface WAEntityMapping : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
+ (instancetype _Nonnull)new NS_UNAVAILABLE;

/**
* Retrieve the mapping for an entity name
*
* @param name The name of the entity
* @param entityName The name of the entity
*
* @return the corresponding mapping
*/
+ (instancetype)mappingForEntityName:(NSString *)entityName;
+ (instancetype _Nonnull)mappingForEntityName:(NSString *_Nonnull)entityName;

- (instancetype)initWithEntityName:(NSString *)entityName NS_DESIGNATED_INITIALIZER;
- (instancetype _Nonnull)initWithEntityName:(NSString *_Nonnull)entityName NS_DESIGNATED_INITIALIZER;

/**
* Add attributes mappings
*
* @param attributeMappings A dictionary which represents source <-> destination. The key is the source property name, the value is the destination property name (your class file)
*/
- (void)addAttributeMappingsFromDictionary:(NSDictionary *)attributeMappings;
- (void)addAttributeMappingsFromDictionary:(NSDictionary *_Nonnull)attributeMappings;

/**
* Add custom mappings. For example, if you want to uppercase a value, or use a data transformer.
Expand All @@ -46,7 +46,7 @@
* @param destinationProperty the destination property name (ex: `googlePlaceID`)
* @param mappingBlock the block used to transform the value from JSON to the object
*/
- (void)addMappingFromSourceProperty:(NSString *)sourceProperty toDestinationProperty:(NSString *)destinationProperty withBlock:(WAMappingBlock)mappingBlock;
- (void)addMappingFromSourceProperty:(NSString *_Nonnull)sourceProperty toDestinationProperty:(NSString *_Nonnull)destinationProperty withBlock:(_Nullable WAMappingBlock)mappingBlock;

/**
* Add custom mappings with a reverse block for turning object into JSON
Expand All @@ -56,42 +56,42 @@
* @param mappingBlock the block used to transform the value from JSON to the object
* @param reverseMappingBlock the block used to transform the value from the object to JSON
*/
- (void)addMappingFromSourceProperty:(NSString *)sourceProperty toDestinationProperty:(NSString *)destinationProperty withBlock:(WAMappingBlock)mappingBlock reverseBlock:(WAMappingBlock)reverseMappingBlock;
- (void)addMappingFromSourceProperty:(NSString *_Nonnull)sourceProperty toDestinationProperty:(NSString *_Nonnull)destinationProperty withBlock:(_Nullable WAMappingBlock)mappingBlock reverseBlock:(_Nullable WAMappingBlock)reverseMappingBlock;

/**
* You can add some relation ship mappings.
*
* @param relationshipMapping The relation ship mapping
*/
- (void)addRelationshipMapping:(WARelationshipMapping *)relationshipMapping;
- (void)addRelationshipMapping:(WARelationshipMapping *_Nonnull)relationshipMapping;

/**
* Identification attribute property name of the destination object
*/
@property (nonatomic, strong) NSString *identificationAttribute;
@property (nonatomic, strong) NSString *_Nullable identificationAttribute;
/**
* Identification attribute property name of the source object (dictionary)
*/
@property (nonatomic, readonly) NSString *inverseIdentificationAttribute;
@property (nonatomic, readonly) NSString *_Nullable inverseIdentificationAttribute;

/**
* The entity name. The class name for classic objects and the entity name in CoreData for example.
*/
@property (nonatomic, strong, readonly) NSString *entityName;
@property (nonatomic, strong, readonly) NSString *_Nonnull entityName;

/**
* A dictionary which represents all the properties used for mapping. The keys are the destination properties name
*/
@property (nonatomic, strong, readonly) NSDictionary<NSString *, WAPropertyMapping *> *attributeMappings;
@property (nonatomic, strong, readonly) NSDictionary<NSString *, WAPropertyMapping *> *_Nullable attributeMappings;

/**
* A dictionary which represents all the properties used for reversed mapping. The keys are the source properties name
*/
@property (nonatomic, strong, readonly) NSDictionary<NSString *, WAPropertyMapping *> *inverseAttributeMappings;
@property (nonatomic, strong, readonly) NSDictionary<NSString *, WAPropertyMapping *> *_Nullable inverseAttributeMappings;

/**
* An array representing all the relation ships on an object
*/
@property (nonatomic, strong, readonly) NSArray *relationshipMappings;
@property (nonatomic, strong, readonly) NSArray *_Nullable relationshipMappings;

@end
20 changes: 10 additions & 10 deletions Files/WAMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
@class WAEntityMapping;
@protocol WAStoreProtocol;

typedef void (^WAMapperProgressBlock)(NSProgress *progress);
typedef void (^WAMapperCompletionBlock)(NSArray *mappedObjects, NSError *error);
typedef void (^WAMapperProgressBlock)(NSProgress *_Nullable progress);
typedef void (^WAMapperCompletionBlock)(NSArray *_Nullable mappedObjects, NSError *_Nullable error);

/**
This class will transform a dictionary representation to an object
Expand All @@ -22,8 +22,8 @@ typedef void (^WAMapperCompletionBlock)(NSArray *mappedObjects, NSError *error);
*/
@interface WAMapper : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
+ (instancetype _Nonnull)new NS_UNAVAILABLE;

/**
* Init the mapper with a store
Expand All @@ -32,12 +32,12 @@ typedef void (^WAMapperCompletionBlock)(NSArray *mappedObjects, NSError *error);
*
* @return an instance of the mapper
*/
- (instancetype)initWithStore:(id <WAStoreProtocol>)store NS_DESIGNATED_INITIALIZER;
- (instancetype _Nonnull)initWithStore:(_Nonnull id <WAStoreProtocol>)store NS_DESIGNATED_INITIALIZER;

/**
* @see `initWithStore:`
*/
+ (instancetype)newMapperWithStore:(id <WAStoreProtocol>)store;
+ (instancetype _Nonnull)newMapperWithStore:(_Nonnull id <WAStoreProtocol>)store;

/**
* Map a dictionary representation to the objects
Expand All @@ -46,18 +46,18 @@ typedef void (^WAMapperCompletionBlock)(NSArray *mappedObjects, NSError *error);
* @param mapping the mapping used to map the objects
* @param completion a completion block called when all objects have been mapped
*/
- (void)mapFromRepresentation:(id)json mapping:(WAEntityMapping *)mapping completion:(WAMapperCompletionBlock)completion;
- (void)mapFromRepresentation:(_Nonnull id)json mapping:(WAEntityMapping *_Nonnull)mapping completion:(_Nonnull WAMapperCompletionBlock)completion;

/**
* Add a default mapping block for a class. For example, you could have an API returning dates all with the same format. You can register the transformation once here.
*
* @param mappingBlock the mapping block called to transform the value
* @param destinationClass the destination class
*/
- (void)addDefaultMappingBlock:(WAMappingBlock)mappingBlock forDestinationClass:(Class)destinationClass;
- (void)addDefaultMappingBlock:(_Nonnull WAMappingBlock)mappingBlock forDestinationClass:(_Nonnull Class)destinationClass;

@property (nonatomic, strong, readonly) id <WAStoreProtocol> store;
@property (nonatomic, strong, readonly) _Nonnull id <WAStoreProtocol> store;

@property (strong, readonly) NSProgress *progress;
@property (strong, readonly) NSProgress *_Nullable progress;

@end
4 changes: 2 additions & 2 deletions Files/WAMappingRegistrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @param mapping the mapping to register
*/
- (void)registerMapping:(WAEntityMapping *)mapping;
- (void)registerMapping:(WAEntityMapping *_Nonnull)mapping;

/**
* Retrieve a registered mapping from entity name
Expand All @@ -29,6 +29,6 @@
*
* @return an existing entity mapping or nil
*/
- (WAEntityMapping *)mappingForEntityName:(NSString *)entityName;
- ( WAEntityMapping *_Nullable )mappingForEntityName:(NSString *_Nonnull)entityName;

@end
4 changes: 2 additions & 2 deletions Files/WAMergeableCollectionProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@protocol WAMergeableCollectionProtocol <NSObject>

- (instancetype)wa_collectionMergedWith:(id <WAMergeableCollectionProtocol>)toMerge;
- (instancetype)wa_collectionMinus:(id <WAMergeableCollectionProtocol>)toRemove;
- (instancetype _Nonnull)wa_collectionMergedWith:(_Nonnull id <WAMergeableCollectionProtocol>)toMerge;
- (instancetype _Nonnull)wa_collectionMinus:(_Nonnull id <WAMergeableCollectionProtocol>)toRemove;

@end
6 changes: 3 additions & 3 deletions Files/WANSCodingStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
@interface WANSCodingStore : NSObject <WAStoreProtocol>

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
+ (instancetype _Nonnull)new NS_UNAVAILABLE;

/**
* Init the store with an archive path used to store all your objects
Expand All @@ -24,6 +24,6 @@
*
* @return an NSCoding store
*/
- (instancetype)initWithArchivePath:(NSString *)archivePath NS_DESIGNATED_INITIALIZER;
- (instancetype _Nonnull)initWithArchivePath:(NSString *_Nonnull)archivePath NS_DESIGNATED_INITIALIZER;

@end
16 changes: 8 additions & 8 deletions Files/WAPropertyMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
@interface WAPropertyMapping : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
+ (instancetype _Nonnull)new NS_UNAVAILABLE;

/**
* Create a property mapping
Expand All @@ -27,16 +27,16 @@
*
* @return return a property mapping instance
*/
- (instancetype)initWithSourcePropertyName:(NSString *)sourcePropertyName destinationPropertyName:(NSString *)destinationPropertyName mappingBlock:(WAMappingBlock)mappingBlock reverseMappingBlock:(WAMappingBlock)reverseMappingBlock;
- (instancetype _Nonnull)initWithSourcePropertyName:(NSString *_Nonnull)sourcePropertyName destinationPropertyName:(NSString *_Nonnull)destinationPropertyName mappingBlock:(_Nullable WAMappingBlock)mappingBlock reverseMappingBlock:(_Nullable WAMappingBlock)reverseMappingBlock;

/**
* @see `initWithSourcePropertyName: destinationPropertyName: mappingBlock: reverseMappingBlock:`
*/
+ (instancetype)propertyMappingWithSourcePropertyName:(NSString *)sourcePropertyName destinationPropertyName:(NSString *)destinationPropertyName mappingBlock:(WAMappingBlock)mappingBlock reverseMappingBlock:(WAMappingBlock)reverseMappingBlock;
+ (instancetype _Nonnull)propertyMappingWithSourcePropertyName:(NSString *_Nonnull)sourcePropertyName destinationPropertyName:(NSString *_Nonnull)destinationPropertyName mappingBlock:(_Nullable WAMappingBlock)mappingBlock reverseMappingBlock:(_Nullable WAMappingBlock)reverseMappingBlock;

@property (nonatomic, strong, readonly) NSString *sourcePropertyName;
@property (nonatomic, strong, readonly) NSString *destinationPropertyName;
@property (nonatomic, copy, readonly ) WAMappingBlock mappingBlock;
@property (nonatomic, copy, readonly ) WAMappingBlock reverseMappingBlock;
@property (nonatomic, strong, readonly) NSString *_Nonnull sourcePropertyName;
@property (nonatomic, strong, readonly) NSString *_Nonnull destinationPropertyName;
@property (nonatomic, copy, readonly ) _Nullable WAMappingBlock mappingBlock;
@property (nonatomic, copy, readonly ) _Nullable WAMappingBlock reverseMappingBlock;

@end
10 changes: 5 additions & 5 deletions Files/WAPropertyTransformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

@interface WAPropertyTransformation : NSObject

+ (id)propertyValue:(id)initialValue fromPropertyName:(NSString *)propertyName forObject:(id)object;
+ (NSString *)propertyTypeStringRepresentationFromPropertyName:(NSString *)propertyName forObject:(id)object;
+ (BOOL)isClassACollection:(Class)class;
+ (BOOL)isClassAMutableCollection:(Class)class;
+ (id)convertObject:(id)object toClass:(Class)destinationClass;
+ (id _Nullable)propertyValue:(_Nullable id)initialValue fromPropertyName:(NSString *_Nonnull)propertyName forObject:(_Nonnull id)object;
+ (NSString *_Nullable)propertyTypeStringRepresentationFromPropertyName:(NSString *_Nonnull)propertyName forObject:(_Nonnull id)object;
+ (BOOL)isClassACollection:(_Nonnull Class)class;
+ (BOOL)isClassAMutableCollection:(_Nonnull Class)class;
+ (id _Nullable)convertObject:(_Nonnull id)object toClass:(_Nonnull Class)destinationClass;

@end
20 changes: 10 additions & 10 deletions Files/WARelationshipMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ typedef enum : NSUInteger {
*/
@interface WARelationshipMapping : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
+ (instancetype _Nonnull)new NS_UNAVAILABLE;

/**
* This is the classic relation ship. eg: `{employees: [{"name": "first employee"}, {"name": "second employee"}]}`
Expand All @@ -33,12 +33,12 @@ typedef enum : NSUInteger {
*
* @return a relationship mapping instance
*/
- (instancetype)initWithSourceProperty:(NSString *)sourceProperty destinationProperty:(NSString *)destinationProperty mapping:(WAEntityMapping *)mapping;
- (instancetype _Nonnull)initWithSourceProperty:(NSString *_Nonnull)sourceProperty destinationProperty:(NSString *_Nonnull)destinationProperty mapping:(WAEntityMapping *_Nonnull)mapping;

/**
* @see `initWithSourceProperty: destinationProperty: mapping:`
*/
+ (instancetype)relationshipMappingFromSourceProperty:(NSString *)sourceProperty toDestinationProperty:(NSString *)destinationProperty withMapping:(WAEntityMapping *)mapping;
+ (instancetype _Nonnull)relationshipMappingFromSourceProperty:(NSString *_Nonnull)sourceProperty toDestinationProperty:(NSString *_Nonnull)destinationProperty withMapping:(WAEntityMapping *_Nonnull)mapping;

/**
* This is the second behavior offered for a relation ship. eg: `{employees: [1, 2]}` or `{chief: 1}`
Expand All @@ -49,12 +49,12 @@ typedef enum : NSUInteger {
*
* @return a relation ship mapping instance
*/
- (instancetype)initWithSourceIdentificationAttribute:(NSString *)sourceIdentificationAttribute destinationProperty:(NSString *)destinationProperty mapping:(WAEntityMapping *)mapping;
- (instancetype _Nonnull)initWithSourceIdentificationAttribute:(NSString *_Nonnull)sourceIdentificationAttribute destinationProperty:(NSString *_Nonnull)destinationProperty mapping:(WAEntityMapping *_Nonnull)mapping;

/**
* @see `initWithSourceIdentificationAttribute: destinationProperty: mapping:`
*/
+ (instancetype)relationshipMappingFromSourceIdentificationAttribute:(NSString *)sourceIdentificationAttribute toDestinationProperty:(NSString *)destinationProperty withMapping:(WAEntityMapping *)mapping;
+ (instancetype _Nonnull)relationshipMappingFromSourceIdentificationAttribute:(NSString *_Nonnull)sourceIdentificationAttribute toDestinationProperty:(NSString *_Nonnull)destinationProperty withMapping:(WAEntityMapping *_Nonnull)mapping;

/**
* The relation ship policy. Default is `WARelationshipPolicyAssign`
Expand All @@ -65,9 +65,9 @@ typedef enum : NSUInteger {
*/
@property (nonatomic, assign) WARelationshipPolicy relationshipPolicy;

@property (nonatomic, readonly) NSString *sourceProperty;
@property (nonatomic, readonly) NSString *sourceIdentificationAttribute;
@property (nonatomic, readonly) NSString *destinationProperty;
@property (nonatomic, readonly) WAEntityMapping *mapping;
@property (nonatomic, readonly) NSString *_Nullable sourceProperty;
@property (nonatomic, readonly) NSString *_Nullable sourceIdentificationAttribute;
@property (nonatomic, readonly) NSString *_Nonnull destinationProperty;
@property (nonatomic, readonly) WAEntityMapping *_Nonnull mapping;

@end
14 changes: 7 additions & 7 deletions Files/WAReverseMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@class WAEntityMapping;

typedef BOOL (^WAReverseMapperShouldMapRelationshipBlock)(NSString *sourceRelationShip);
typedef BOOL (^WAReverseMapperShouldMapRelationshipBlock)(NSString *_Nonnull sourceRelationShip);

/**
* This class performs a reverse mapper by turning objects back into dictionaries
Expand All @@ -22,22 +22,22 @@ typedef BOOL (^WAReverseMapperShouldMapRelationshipBlock)(NSString *sourceRelati
/**
* Turns objects into a dictionary
*
* @param objects the objects you need to turns into dictionary
* @param mapping the mapping used to reverse map the objects
* @param shouldMapRelationship a block called if you want to avoid some relationships to be reversed mapped. Map everything by default.
* @param objects the objects you need to turns into dictionary
* @param mapping the mapping used to reverse map the objects
* @param shouldMapRelationshipBlock a block called if you want to avoid some relationships to be reversed mapped. Map everything by default.
*
* @return an array of dictionary which are a representation of the objects
*/
- (NSArray <NSDictionary *>*)reverseMapObjects:(NSArray *)objects fromMapping:(WAEntityMapping *)mapping shouldMapRelationship:(WAReverseMapperShouldMapRelationshipBlock)shouldMapRelationshipBlock error:(NSError **)error;
- (NSArray <NSDictionary *>*_Nullable)reverseMapObjects:(NSArray *_Nonnull)objects fromMapping:(WAEntityMapping *_Nonnull)mapping shouldMapRelationship:(_Nullable WAReverseMapperShouldMapRelationshipBlock)shouldMapRelationshipBlock error:(NSError *_Nullable*_Nullable)error;

/**
* Add a reverse default mapping block for a class. For example, you could have an API returning dates all with the same format. You can register the transformation once here.
*
* @param reverseMappingBlock the reverse mapping block called to transform the value
* @param destinationClass the destination class
*/
- (void)addReverseDefaultMappingBlock:(WAMappingBlock)reverseMappingBlock forDestinationClass:(Class)destinationClass;
- (void)addReverseDefaultMappingBlock:(_Nonnull WAMappingBlock)reverseMappingBlock forDestinationClass:(_Nonnull Class)destinationClass;

@property (strong, readonly) NSProgress *progress;
@property (strong, readonly) NSProgress *_Nullable progress;

@end
Loading

0 comments on commit b7e3a78

Please sign in to comment.