Я настраивал и тестировал Core Data в своем приложении, и все работает отлично на месте; Однако, как только я включаю ICloud через:Использование iCloud Core Data NSArray-принятие метод
NSDictionary *options;
if ([self iCloudEnabled]) {
options = @{NSSQLitePragmasOption: @{@"journal_mode" : @"DELETE"},
NSPersistentStoreUbiquitousContentNameKey : @"iCloudStore"};
[self subscribeToNotifications];
} else
options = @{NSSQLitePragmasOption: @{@"journal_mode" : @"DELETE"}};
И запустить мое приложение, я получаю следующее сообщение об ошибке спама в консоли:
*** ERROR: this process has called an NSArray-taking method, such as initWithArray:, and passed in an NSSet object. This is being worked-around for now, but will soon cause you grief.
Когда эта ошибка делается печать, кажется, что все работает как обычно.
Единственные другие связанные вопросы, которые я мог найти, были here и here, и ни один из них не был полезен.
Я даже не могу найти нигде, где говорится, что означает эта ошибка.
Любая помощь приветствуется.
EDIT: Из того, что я обнаружил, это происходит после инициализации моего управляемого объекта ObjectContext и до того, как на консоль будет напечатана «Использование локального хранилища: 0». Проблема в том, что я не знаю, что выполняется за это время (потому что я ничего не звоню); это похоже на фоновый поток.
EDIT2: Следует также упомянуть, что это происходит только при первом запуске приложения (в разовой настройке iCloud).
EDIT3: Вот код, который инициализирует свой контекст:
- (NSURL *)coreDataLocalURL {
// The directory the application uses to store the Core Data store file.
NSURL *result = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
result = [result URLByAppendingPathComponent:@"TheAnglersLog"];
NSError *e;
if (![[NSFileManager defaultManager] fileExistsAtPath:result.path])
// create TheAnglersLog directory if it doesn't exist
[[NSFileManager defaultManager] createDirectoryAtPath:result.path
withIntermediateDirectories:NO
attributes:nil
error:&e];
return result;
}
- (NSManagedObjectModel *)managedObjectModel {
// The managed object model for the application. It is a fatal error for the application not to be able to find and load its model.
if (_managedObjectModel != nil)
return _managedObjectModel;
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"TheAnglersLog" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return _managedObjectModel;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it.
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
// Create the coordinator and store
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSURL *storeURL = [[self coreDataLocalURL] URLByAppendingPathComponent:@"TheAnglersLog.sqlite"];
NSError *error = nil;
NSString *failureReason = @"There was an error creating or loading the application's saved data.";
NSDictionary *options;
if ([self iCloudEnabled]) {
options = @{NSSQLitePragmasOption: @{@"journal_mode" : @"DELETE"},
NSPersistentStoreUbiquitousContentNameKey : @"TheAnglersLogCloudStore"};
[self subscribeToNotifications];
} else
options = @{NSSQLitePragmasOption: @{@"journal_mode" : @"DELETE"}};
NSLog(@"Is iCloud enabled? %@", [self iCloudEnabled] ? @"YES" : @"NO");
NSPersistentStore *store;
if (!(store = [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])) {
// Report any errors we got.
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";
dict[NSLocalizedFailureReasonErrorKey] = failureReason;
dict[NSUnderlyingErrorKey] = error;
error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
NSLog(@"Error in persistentStoreCoordinator: %@, %@", error, [error userInfo]);
}
NSLog(@"Core Data URL: %@", [store URL]);
return _persistentStoreCoordinator;
}
- (NSManagedObjectContext *)managedObjectContext {
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
if (_managedObjectContext != nil) {
return _managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (!coordinator) {
return nil;
}
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
return _managedObjectContext;
}
Я получаю такое же зловещее предупреждение в своей программе. Я использую iCloud с моими основными данными. Подкласс подпроцесса моего объекта имеет отношение «один-много» к другому объекту и его объявлено как NSOrderedSet. Когда происходит повсеместное изменение, я получаю это предупреждение. Я отправлю ответ, если я смогу заставить его уйти, не выключая iCloud. – Garret