我使用 MagicalImport(2.1 版)MR_importFromArray 方法导入了一个 json 数组。我正在尝试使用 MR_findAll 检索导入的 NSManagedObjects,但没有任何成功。以下是我迄今为止尝试过的变体:
//Attempt 1
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
[Thread MR_importFromArray:threadsData];
} completion:^(BOOL success, NSError *error) {
NSArray *allThreads = [Thread MR_findAll];
}];
//Attempt 2
[MagicalRecord saveUsingCurrentThreadContextWithBlock:^(NSManagedObjectContext *localContext) {
[Thread MR_importFromArray:threadsData inContext:localContext];
} completion:^(BOOL success, NSError *error) {
NSArray *allThreads = [Thread MR_findAllInContext:[NSManagedObjectContext MR_contextForCurrentThread]];
}];
//Attempt 3
NSManagedObjectContext *context =[NSManagedObjectContext MR_defaultContext];
[Thread MR_importFromArray:threadsData inContext:context];
[context MR_saveToPersistentStoreAndWait];
NSArray *allThreads = [Thread MR_findAllInContext:context];
//Attempt 4
[Thread MR_importFromArray:threadsData];
[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreAndWait];
NSArray *allThreads = [Thread MR_findAll];
这是我在控制台中看到的错误:
-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0xb2566e0) NO CHANGES IN ** DEFAULT ** CONTEXT - NOT SAVING
知道我做错了什么吗?