CoreData: error: NULL _cd_rawData but the object is not being turned into a fault

前端 未结 3 408
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 18:39

I occasionally get this error when saving to core data. I cannot manage to recreate it.

Does anyone have any experience with this error;

CoreData: er         


        
相关标签:
3条回答
  • 2020-12-29 19:24

    Reason:

    This happens when the object's context does not belong to the current thread. One of many ways that mistake can manifest itself.

    Debug:

    When the crash occurs do the following:

    1. Check the thread in which the crash occured (Xcode > Debug Navigator)
    2. On the console print, the concurrency type of the NSManagedObjectContext
    3. If the concurrency type is mainQueueConcurrencyType then it needs to be on the main thread otherwise on the background threads.

    Console command to check concurrency type:

    p context.concurrencyType
    

    In the sample command above the NSManagedObjectContext was stored in the variable context

    Console Output:

    (NSManagedObjectContextConcurrencyType) $R4 = mainQueueConcurrencyType
    
    0 讨论(0)
  • 2020-12-29 19:25

    I found the same problem when I tried to read (access) data from a Coredata Store in other thread (not main).

    You can solve this problem by following this suggestion from this link:
    Core Data and threads / Grand Central Dispatch

    0 讨论(0)
  • 2020-12-29 19:33

    After going to several post, this had a better answer https://web.archive.org/web/20150215081345/http://www.cocoabuilder.com:80/archive/cocoa/311615-weird-core-data-crash.html

    0 讨论(0)
提交回复
热议问题