CRLoom 是一个帮助导入、更新和查询 NSManagedObject 的框架
NSManagedObjectImportOperation这是一个通过某种方式创建的 NSOperation 子类。
+ (instanceType)operationWithData:(id)data
managedObjectClass:(Class)class
guaranteedInsert:(BOOL)guaranteedInsert
saveOnBatchSize:(NSUInteger)batchSize
pruneMissingObjects:(BOOL)pruneMissingObjects
useCache:(BOOL)useCache
error:(NSError* __autoreleasing *)error;此操作可以被添加到 NSOperationQueue 中,并将导入数据的工作线程化。设置 useCache 为 YES 将使操作提供 NSCache 以供执行导入工作的线程使用,这将是检查存在对象的第一层,在完全使用fetch请求之前。
NSManagedObject+CRLoom这是一个提供导入和查找 NSManagedObject 的通用实现的类别。导入和搜索方法接受一个 NSManagedObjectContext 作为参数,以便它们可以在不同的线程上工作。
+ (NSArray*)importData:(id)data
intoContext:(NSManagedObjectContext*)moc
withCache:(NSCache*)cache
guaranteedInsert:(BOOL)guaranteedInsert
saveOnBatchSize:(NSUInteger)batchSize
error:(NSError* __autoreleasing *)error;可以提供一个缓存,用于在将数据处理成 NSManagedObject 时作为现有对象的第一层检查位置。在此处提供缓存将确保创建或检索这些共享对象时,它们将存储在缓存中,以减少执行的fetch请求总数。
+ (instancetype)existingObjectWithIdentifierValue:(id)value
inContext:(NSManagedObjectContext*)moc
withCache:(NSCache*)cache
error:(NSError* __autoreleasing *)error;<CRLoomImport>为了使这些方法对一个特定的 NSManagedObject 子类生效,必须实现一些方法。由 <CRLoomImport> 协议提供的需要实现的方法。
返回表示对象唯一标识符的模型(Core Data)键的方法
+ (NSString*)uniqueModelIdentifierKey;返回表示在导入的数据中对象唯一标识符的键的方法(例如,从您的API中获取的JSON中的键)
+ (NSString*)uniqueDataIdentifierKey;一个方法用于使用API中的数据更新对象。这允许在任何给定上下文中执行工作,并确保错误交付,缓存将在完成对核心数据的完整fetch请求之前,用作获取现有关系对象的第一层。
- (BOOL)updateWithData:(NSDictionary*)data
intoContext:(NSManagedObjectContext*)moc
withCache:(NSCache*)cache
error:(NSError**)error;一个方法用于指示模型的数据是否与该对象的 NSDictionary 表示形式相同。
- (BOOL)isIdenticalToData:(NSDictionary*)data;NSManagedObject 子类也可以选择实现方法以返回用于“匹配”对象的 NSPredicate。
+ (NSPredicate*)predicateWithIdentiferValue:(id)identifierValue;
+ (NSPredicate*)predicateWithIdentiferCollection:(NSArray*)identifierCollection;