NSManagedObjectContext(KBAImportExtensions)

@interface NSManagedObjectContext (KBAImportExtensions)

/**
 Set and get the key used for testing equality when importing. If you require a custom key, this should be set before calling `KBA_importJSON:entityOrder:entityMapping:completion:`.
 
 The default is @"identity".
 */
@property (class,copy,nonatomic,null_resettable) NSString *KBA_defaultIdentityKey;
/**
 Set and get the date formatter used to convert between JSON and NSDate objects.
 
 The default is an NSDateFormatter with @"yyyy-MM-dd'T'HH:mm:ssZZZZZ" as its date format.
 */
@property (class,strong,nonatomic,null_resettable) NSDateFormatter *KBA_defaultDateFormatter;

/**
 Get the object responsible for mapping between entity properties and JSON keys.
 
 The default is an instance of KBADefaultManagedObjectPropertyMapping.
 
 @param entityName The name of the entity
 @return The property mapping object for the entity with name
 */
+ (id<KBAManagedObjectPropertyMapping>)KBA_propertyMappingForEntityNamed:(NSString *)entityName;
/**
 Register a property mapping for a particular entity.
 
 @param propertyMapping An object conforming to KBAManagedObjectPropertyMapping
 @param entityName The name of the entity
 */
+ (void)KBA_registerPropertyMapping:(nullable id<KBAManagedObjectPropertyMapping>)propertyMapping forEntityNamed:(NSString *)entityName;

/**
 Returns a NSManagedObject of entityName by mapping keys and values in dictionary using propertyMapping.
 
 @param dictionary The dictionary of property/relationship key/value pairs
 @param entityName The name of the entity to create
 @param propertyMapping The property mapping to use during creation
 @param error If the method returns nil, an error describing the reason for failure
 @return The managed object
 */
- (nullable __kindof NSManagedObject *)KBA_managedObjectWithDictionary:(NSDictionary *)dictionary entityName:(NSString *)entityName propertyMapping:(id<KBAManagedObjectPropertyMapping>)propertyMapping error:(NSError *__autoreleasing *)error;

/**
 Imports the provided JSON, creating managed objects for each entry using entityMapping, which maps between JSON keys and entity names. Invokes the completion block when the operation is finished.
 
 @param JSON A collection conforming to NSFastEnumeration, if a NSDictionary is provided, entityOrder can be nil
 @param entityOrder The order to import the entities in JSON
 @param entityMapping The entity mapping
 @param completion The completion block invoked when the operation is finished
 */
- (void)KBA_importJSON:(id<NSFastEnumeration,NSObject>)JSON entityOrder:(nullable NSArray *)entityOrder entityMapping:(nullable id<KBAManagedObjectEntityMapping>)entityMapping completion:(void(^)(BOOL success, NSError *_Nullable error))completion;

@end

Undocumented

  • Set and get the key used for testing equality when importing. If you require a custom key, this should be set before calling KBA_importJSON:entityOrder:entityMapping:completion:.

    The default is @“identity”.

    Declaration

    Objective-C

    @property (class, nonatomic, copy, null_resettable) NSString *KBA_defaultIdentityKey;
  • Set and get the date formatter used to convert between JSON and NSDate objects.

    The default is an NSDateFormatter with @“yyyy-MM-dd’T'HH:mm:ssZZZZZ” as its date format.

    Declaration

    Objective-C

    @property (class, nonatomic, strong, null_resettable) NSDateFormatter *KBA_defaultDateFormatter;
  • Get the object responsible for mapping between entity properties and JSON keys.

    The default is an instance of KBADefaultManagedObjectPropertyMapping.

    Declaration

    Objective-C

    + (nonnull id<KBAManagedObjectPropertyMapping>)
        KBA_propertyMappingForEntityNamed:(nonnull NSString *)entityName;

    Parameters

    entityName

    The name of the entity

    Return Value

    The property mapping object for the entity with name

  • Register a property mapping for a particular entity.

    Declaration

    Objective-C

    + (void)KBA_registerPropertyMapping:
                (nullable id<KBAManagedObjectPropertyMapping>)propertyMapping
                         forEntityNamed:(nonnull NSString *)entityName;

    Parameters

    propertyMapping

    An object conforming to KBAManagedObjectPropertyMapping

    entityName

    The name of the entity

  • Returns a NSManagedObject of entityName by mapping keys and values in dictionary using propertyMapping.

    Declaration

    Objective-C

    - (nullable __kindof NSManagedObject *)
        KBA_managedObjectWithDictionary:(nonnull NSDictionary *)dictionary
                             entityName:(nonnull NSString *)entityName
                        propertyMapping:
                            (nonnull id<KBAManagedObjectPropertyMapping>)
                                propertyMapping
                                  error:(NSError *_Nullable *_Nullable)error;

    Parameters

    dictionary

    The dictionary of property/relationship key/value pairs

    entityName

    The name of the entity to create

    propertyMapping

    The property mapping to use during creation

    error

    If the method returns nil, an error describing the reason for failure

    Return Value

    The managed object

  • Imports the provided JSON, creating managed objects for each entry using entityMapping, which maps between JSON keys and entity names. Invokes the completion block when the operation is finished.

    Declaration

    Objective-C

    - (void)KBA_importJSON:(nonnull id<NSFastEnumeration, NSObject>)JSON
               entityOrder:(nullable NSArray *)entityOrder
             entityMapping:(nullable id<KBAManagedObjectEntityMapping>)entityMapping
                completion:(nonnull void (^)(BOOL, NSError *_Nullable))completion;

    Parameters

    JSON

    A collection conforming to NSFastEnumeration, if a NSDictionary is provided, entityOrder can be nil

    entityOrder

    The order to import the entities in JSON

    entityMapping

    The entity mapping

    completion

    The completion block invoked when the operation is finished