Skip to content

Commit

Permalink
annotate API with nullability annotations. Remove deprecated API. Sta…
Browse files Browse the repository at this point in the history
…te ek_formatterForCurrentThread as deprecated.
  • Loading branch information
DenTelezhkin committed Jul 1, 2016
1 parent d301760 commit adbc411
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 74 deletions.
6 changes: 5 additions & 1 deletion EasyMapping/EKCoreDataImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
@import CoreData;
#import "EKManagedObjectMapping.h"

NS_ASSUME_NONNULL_BEGIN

/**
`EKCoreDataImporter` is internal EasyMapping class and is used by `EKManagedObjectMapper` to manage CoreData imports and make them fast and efficient. It basically does 3 things:
Expand Down Expand Up @@ -75,8 +77,10 @@
@result managed object
*/
- (id)existingObjectForRepresentation:(id)representation mapping:(EKManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context;
- (nullable id)existingObjectForRepresentation:(id)representation mapping:(EKManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context;

- (void)cacheObject:(NSManagedObject *)object withMapping:(EKManagedObjectMapping *)mapping;

@end

NS_ASSUME_NONNULL_END
5 changes: 4 additions & 1 deletion EasyMapping/EKManagedObjectMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#import <CoreData/CoreData.h>
#import "EKManagedObjectMapping.h"

NS_ASSUME_NONNULL_BEGIN

/**
`EKManagedObjectMapper` is used to create and fill CoreData objects. Internally, it uses `EKCoreDataImporter` class to speed up data imports. You can find more info on this in project's readme.
*/
Expand Down Expand Up @@ -97,5 +99,6 @@
withMapping:(EKManagedObjectMapping *)mapping
fetchRequest:(NSFetchRequest*)fetchRequest
inManagedObjectContext:(NSManagedObjectContext *)context;

@end

NS_ASSUME_NONNULL_END
8 changes: 6 additions & 2 deletions EasyMapping/EKManagedObjectMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#define EKDesignatedInitializer(__SEL__) __attribute__((unavailable("Invoke the designated initializer `" # __SEL__ "` instead.")))

NS_ASSUME_NONNULL_BEGIN

/**
`EKManagedObjectMapping` is a subclass of `EKObjectMapping`, intended to be used with CoreData objects.
*/
Expand All @@ -40,7 +42,7 @@
/**
Primary key of CoreData objects
*/
@property (nonatomic, strong) NSString *primaryKey;
@property (nonatomic, strong, nullable) NSString *primaryKey;

-(void)mapKeyPath:(NSString *)keyPath toProperty:(NSString *)property withValueBlock:(EKManagedMappingValueBlock)valueBlock;

Expand Down Expand Up @@ -100,7 +102,7 @@
@result property mapping
*/
- (EKPropertyMapping *)primaryKeyPropertyMapping;
- (nullable EKPropertyMapping *)primaryKeyPropertyMapping;

#pragma mark - unavalable methods

Expand All @@ -125,3 +127,5 @@
+ (instancetype)mappingForClass:(Class)objectClass withRootPath:(NSString *)rootPath
withBlock:(void (^)(EKObjectMapping *mapping))mappingBlock EKDesignatedInitializer(mappingForEntityName:withRootPath:withBlock);
@end

NS_ASSUME_NONNULL_END
8 changes: 3 additions & 5 deletions EasyMapping/EKManagedObjectModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import <CoreData/CoreData.h>
#import "EKMappingProtocol.h"

NS_ASSUME_NONNULL_BEGIN

/**
EKManagedObjectModel is a convenience base class for NSManagedObject subclasses. It allows creating CoreData objects from JSON representation and vice versa.
*/
Expand Down Expand Up @@ -39,8 +41,4 @@

@end

@interface EKManagedObjectModel(Deprecated)

- (NSDictionary *)serializedObject __deprecated_msg("Use serializedObjectInContext instead");

@end
NS_ASSUME_NONNULL_END
5 changes: 0 additions & 5 deletions EasyMapping/EKManagedObjectModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ - (NSDictionary *)serializedObjectInContext:(NSManagedObjectContext *)context
fromContext:context];
}

-(NSDictionary *)serializedObject
{
return [self serializedObjectInContext:nil];
}

#pragma mark - EKManagedMappingProtocol

+(EKManagedObjectMapping *)objectMapping
Expand Down
8 changes: 6 additions & 2 deletions EasyMapping/EKMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#import "EKObjectMapping.h"

NS_ASSUME_NONNULL_BEGIN

/**
`EKMapper` provides an interface to create objective-c object from JSON representation, using `EKObjectMapping` class. For creating CoreData objects, use `EKManagedObjectMapper` class.
*/
Expand All @@ -38,7 +40,7 @@
@result mapped object
*/
+ (id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation
+ (nullable id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation
withMapping:(EKObjectMapping *)mapping;

/**
Expand All @@ -65,7 +67,9 @@
@result array of mapped objects
*/
+ (NSArray *)arrayOfObjectsFromExternalRepresentation:(NSArray *)externalRepresentation
+ (nullable NSArray *)arrayOfObjectsFromExternalRepresentation:(NSArray *)externalRepresentation
withMapping:(EKObjectMapping *)mapping;

@end

NS_ASSUME_NONNULL_END
12 changes: 8 additions & 4 deletions EasyMapping/EKMappingBlocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

typedef id(^EKMappingValueBlock)(NSString *key, id value);
typedef id(^EKMappingReverseBlock)( id value);
NS_ASSUME_NONNULL_BEGIN

typedef id(^EKManagedMappingValueBlock)(NSString * key, id value, NSManagedObjectContext * context);
typedef id(^EKManagedMappingReverseValueBlock)(id value, NSManagedObjectContext * context);
typedef _Nullable id(^EKMappingValueBlock)(NSString *key, _Nullable id value);
typedef _Nullable id(^EKMappingReverseBlock)(_Nullable id value);

typedef _Nullable id(^EKManagedMappingValueBlock)(NSString * key, _Nullable id value, NSManagedObjectContext * context);
typedef _Nullable id(^EKManagedMappingReverseValueBlock)(_Nullable id value, NSManagedObjectContext * context);

@interface EKMappingBlocks: NSObject

Expand All @@ -37,3 +39,5 @@ typedef id(^EKManagedMappingReverseValueBlock)(id value, NSManagedObjectContext

@end

NS_ASSUME_NONNULL_END

4 changes: 4 additions & 0 deletions EasyMapping/EKMappingProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#import "EKObjectMapping.h"
#import "EKManagedObjectMapping.h"

NS_ASSUME_NONNULL_BEGIN

/**
EKMappingProtocol must be implemented by NSObject subclasses, that will be mapped from JSON representation.
Expand Down Expand Up @@ -41,3 +43,5 @@
+(EKManagedObjectMapping *)objectMapping;

@end

NS_ASSUME_NONNULL_END
25 changes: 6 additions & 19 deletions EasyMapping/EKObjectMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

@protocol EKMappingProtocol;

NS_ASSUME_NONNULL_BEGIN

/**
`EKObjectMapping` class is used to define mappings between JSON representation and objective-c object.
*/
Expand Down Expand Up @@ -229,7 +231,7 @@
- (void) hasOne:(Class)objectClass
forDictionaryFromKeyPaths:(NSArray *)keyPaths
forProperty:(NSString *)property
withObjectMapping:(EKObjectMapping *)objectMapping;
withObjectMapping:(nullable EKObjectMapping *)objectMapping;

/**
Map to-one relationship for keyPath.
Expand All @@ -242,7 +244,7 @@ forDictionaryFromKeyPaths:(NSArray *)keyPaths
@warning If you have recursive mappings, do not use this method, cause it can cause infinite recursion to happen. Or you need to handle recursive mappings situation by yourself, subclassing EKObjectMapping and providing different mappings for different mapping levels.
*/
- (void)hasOne:(Class)objectClass forKeyPath:(NSString *)keyPath forProperty:(NSString *)property withObjectMapping:(EKObjectMapping*)objectMapping;
- (void)hasOne:(Class)objectClass forKeyPath:(NSString *)keyPath forProperty:(NSString *)property withObjectMapping:(nullable EKObjectMapping*)objectMapping;


/**
Expand Down Expand Up @@ -276,23 +278,8 @@ forDictionaryFromKeyPaths:(NSArray *)keyPaths
@warning If you have recursive mappings, do not use this method, cause it can cause infinite recursion to happen. Or you need to handle recursive mappings situation by yourself, subclassing EKObjectMapping and providing different mappings for different mapping levels.
*/
-(void)hasMany:(Class)objectClass forKeyPath:(NSString *)keyPath forProperty:(NSString *)property withObjectMapping:(EKObjectMapping*)objectMapping;
-(void)hasMany:(Class)objectClass forKeyPath:(NSString *)keyPath forProperty:(NSString *)property withObjectMapping:(nullable EKObjectMapping*)objectMapping;

@end

@interface EKObjectMapping(Deprecated)

/**
This method is deprecated and may be removed in the future releases. Please use `mapKeyPath:toProperty:withDateFormatter: method`.
Map JSON keyPath to object property. This method assumes, that value contains NSString, that can be transformed into NSDate by NSDateFormatter. Default timezone is GMT. Transformation is done by `EKTransformer` class.
@param keyPath JSON keypath, that will be used by valueForKeyPath: method
@param property Property name.
@param dateFormat Date format
*/
- (void)mapKeyPath:(NSString *)keyPath toProperty:(NSString *)property withDateFormat:(NSString *)dateFormat __deprecated;

@end
NS_ASSUME_NONNULL_END
5 changes: 0 additions & 5 deletions EasyMapping/EKObjectMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ - (void)mapKeyPath:(NSString *)keyPath toProperty:(NSString *)property
[self addPropertyMappingToDictionary:mapping];
}

- (void)mapKeyPath:(NSString *)keyPath toProperty:(NSString *)property withDateFormat:(NSString *)dateFormat
{
[self mapKeyPath:keyPath toProperty:property withDateFormatter:[NSDateFormatter ek_formatterForCurrentThread]];
}

-(void)mapKeyPath:(NSString *)keyPath toProperty:(NSString *)property withDateFormatter:(NSDateFormatter *)formatter
{
NSParameterAssert(keyPath);
Expand Down
4 changes: 4 additions & 0 deletions EasyMapping/EKObjectModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import <Foundation/Foundation.h>
#import "EKMappingProtocol.h"

NS_ASSUME_NONNULL_BEGIN

/**
EKModel is convenience base class, that allows transforming JSON objects to NSObjects and vice versa.
*/
Expand Down Expand Up @@ -41,3 +43,5 @@
- (NSDictionary *)serializedObject;

@end

NS_ASSUME_NONNULL_END
24 changes: 14 additions & 10 deletions EasyMapping/EKPropertyHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
#import "EKPropertyMapping.h"
#import "EKObjectMapping.h"

NS_ASSUME_NONNULL_BEGIN

/**
`EKPropertyHelper` is internal EasyMapping class, that works with objective-c runtime to get and set values of properties.
*/
@interface EKPropertyHelper : NSObject

+ (BOOL)propertyNameIsScalar:(NSString *)propertyName fromObject:(id)object;

+ (id)propertyRepresentation:(NSArray *)array forObject:(id)object withPropertyName:(NSString *)propertyName;
+ (nullable id)propertyRepresentation:(NSArray *)array forObject:(id)object withPropertyName:(NSString *)propertyName;

+ (void) setProperty:(EKPropertyMapping *)propertyMapping
onObject:(id)object
Expand All @@ -48,19 +50,21 @@
respectPropertyType:(BOOL)respectPropertyType
ignoreMissingFields:(BOOL)ignoreMissingFields;

+ (id)getValueOfProperty:(EKPropertyMapping *)propertyMapping
fromRepresentation:(NSDictionary *)representation
ignoreMissingFields:(BOOL)ignoreMissingFields;
+ (nullable id)getValueOfProperty:(EKPropertyMapping *)propertyMapping
fromRepresentation:(NSDictionary *)representation
ignoreMissingFields:(BOOL)ignoreMissingFields;

+ (id)getValueOfManagedProperty:(EKPropertyMapping *)mapping
fromRepresentation:(NSDictionary *)representation
inContext:(NSManagedObjectContext *)context;
+ (nullable id)getValueOfManagedProperty:(EKPropertyMapping *)mapping
fromRepresentation:(NSDictionary *)representation
inContext:(NSManagedObjectContext *)context;

+ (void)setValue:(id)value onObject:(id)object forKeyPath:(NSString *)keyPath;
+ (void)setValue:(nullable id)value onObject:(id)object forKeyPath:(NSString *)keyPath;

+ (void)addValue:(id)value onObject:(id)object forKeyPath:(NSString *)keyPath;

+ (NSDictionary *)extractRootPathFromExternalRepresentation:(NSDictionary *)externalRepresentation
withMapping:(EKObjectMapping *)mapping;
+ (nullable NSDictionary *)extractRootPathFromExternalRepresentation:(NSDictionary *)externalRepresentation
withMapping:(EKObjectMapping *)mapping;

@end

NS_ASSUME_NONNULL_END
12 changes: 8 additions & 4 deletions EasyMapping/EKPropertyMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#import "EKMappingBlocks.h"

NS_ASSUME_NONNULL_BEGIN

/**
`EKPropertyMapping` is a class, that represents relation between representation of a single field in JSON and objective-c model property.
*/
Expand All @@ -42,21 +44,23 @@
/**
Optional block to transform JSON value into objective-C object.
*/
@property (nonatomic, strong) EKMappingValueBlock valueBlock;
@property (nonatomic, strong, nullable) EKMappingValueBlock valueBlock;

/**
Optional block to serialize objective-c object into JSON representation.
*/
@property (nonatomic, strong) EKMappingReverseBlock reverseBlock;
@property (nonatomic, strong, nullable) EKMappingReverseBlock reverseBlock;

/**
Optional block to transform JSON value into CoreData object.
*/
@property (nonatomic, strong) EKManagedMappingValueBlock managedValueBlock;
@property (nonatomic, strong, nullable) EKManagedMappingValueBlock managedValueBlock;

/**
Optional block to serialize CoreData object into JSON representation.
*/
@property (nonatomic, strong) EKManagedMappingReverseValueBlock managedReverseBlock;
@property (nonatomic, strong, nullable) EKManagedMappingReverseValueBlock managedReverseBlock;

@end

NS_ASSUME_NONNULL_END
7 changes: 5 additions & 2 deletions EasyMapping/EKRelationshipMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "EKObjectMapping.h"
#import "EKMappingProtocol.h"

NS_ASSUME_NONNULL_BEGIN

@interface EKRelationshipMapping : NSObject

@property (nonatomic, strong) Class <EKMappingProtocol> objectClass;
Expand All @@ -19,9 +21,10 @@

@property (nonatomic, strong) EKObjectMapping *objectMapping;

@property (nonatomic, strong) NSArray * nonNestedKeyPaths;
@property (nonatomic, strong, nullable) NSArray * nonNestedKeyPaths;

- (NSDictionary *)extractObjectFromRepresentation:(NSDictionary *)representation;
- (nullable NSDictionary *)extractObjectFromRepresentation:(NSDictionary *)representation;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions EasyMapping/EKSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#import "EKObjectMapping.h"
#import "EKManagedObjectMapping.h"

NS_ASSUME_NONNULL_BEGIN

/**
`EKSerializer` is a class, that allows converting objects to their JSON representation, using `EKObjectMapping`. CoreData objects are supported too.
*/
Expand Down Expand Up @@ -81,3 +83,5 @@
withMapping:(EKManagedObjectMapping*)mapping
fromContext:(NSManagedObjectContext *)context;
@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions EasyMapping/NSArray+FlattenArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@

@import Foundation;

NS_ASSUME_NONNULL_BEGIN

@interface NSArray (FlattenArray)

-(NSArray*)ek_flattenedCompactedArray;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit adbc411

Please sign in to comment.