2015-02-05 26 views
2

我一直在我的應用程序中設置和測試核心數據,並且本地一切工作都很棒;然而,當我通過啓用iCloud中:使用啓用iCloud的核心數據NSArray-taking方法

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. 

當這個錯誤是做印刷,一切似乎工作一般。

我能找到的唯一的其他相關問題是herehere,它們都沒有幫助。

我什至不能找到任何說這是什麼錯誤的含義。

任何幫助表示讚賞。

編輯:從我發現它發生在我的managedObjectContext被初始化之後,並且在「使用本地存儲:0」打印到控制檯之前發生。問題是,我不知道當時正在執行什麼(因爲我什麼也沒有打)。它似乎在後臺線程中。編輯2:我還應該提到,這隻會在應用程序第一次啓動時(在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; 
} 
+0

我在我的程序中也收到了同樣不祥的警告。我使用iCloud和我的核心數據。我的託管對象子類與另一個實體具有一對多關係,並將其聲明爲NSOrderedSet。當無處不在的變化被推動時,我得到了這個警告。如果我可以在不關閉iCloud的情況下使其消失,我會發佈一個答案。 – Garret

回答

0

它告訴你準確的問題:某個地方(而不是在您發佈的代碼),你傳遞一個NSSet到一些東西,期待一個NSArrayNSArray已訂購且包含副本,NSSet是無序且重複排他的。它將它轉換爲一套給你,所以它不會崩潰,但抱怨它可能在未來不會繼續這樣做。

+0

這就是我的想法,但找不到任何東西。不過,我會再看一遍。另外,爲什麼只有當我初始化持久性存儲時啓用iCloud纔會出現這種情況? – cohenadair

+0

我沒有修改任何數據。這發生在應用程序啓動時。通常我會加載保存的數據,但此時沒有保存的數據。這發生在我初始化我的managedObjectContext之後。 – cohenadair

+0

初始化上下文的代碼是什麼樣的? –