crash on coredata ios8

2019-03-23 01:08发布

问题:

I have a crash on CoreData when I save :

2014-09-16 09:51:58.273 My_app[2678:105246] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001087413f5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001083dabb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010874132d +[NSException raise:format:] + 205
    3   CoreFoundation                      0x000000010871274f mutateError + 159
    4   CoreData                            0x000000010672ae56 -[_NSSQLGenerator prepareMasterReorderStatementPart2ForRelationship:] + 118
    5   CoreData                            0x0000000106792fd8 -[NSSQLAdapter newCorrelationMasterReorderStatementPart2ForRelationship:] + 72
    6   CoreData                            0x00000001067a9751 -[NSSQLiteConnection writeCorrelationMasterReordersFromTracker:] + 817
    7   CoreData                            0x00000001067aa061 -[NSSQLiteConnection writeCorrelationChangesFromTracker:] + 65
    8   CoreData                            0x000000010679c617 -[NSSQLCore writeChanges] + 1351
    9   CoreData                            0x00000001066dfadf -[NSSQLCore saveChanges:] + 479
    10  CoreData                            0x00000001066b0ee4 -[NSSQLCore executeRequest:withContext:error:] + 484
    11  CoreData                            0x00000001067868f2 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 4354
    12  CoreData                            0x000000010678e7ee gutsOfBlockToNSPersistentStoreCoordinatorPerform + 190
    13  libdispatch.dylib                   0x00000001091e27f4 _dispatch_client_callout + 8
    14  libdispatch.dylib                   0x00000001091c9848 _dispatch_barrier_sync_f_invoke + 365
    15  CoreData                            0x00000001067813d5 _perform + 197
    16  CoreData                            0x00000001066b0ac8 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 504
    17  CoreData                            0x00000001066d9d2d -[NSManagedObjectContext save:] + 1213

The same code works in ios7.

Is there someone who has the same crash ?

回答1:

Just to summarize the comments that helped me resolve this issue:

  • This seems to be a bug in Core Data related to Ordered Many-to-Many Relationships
  • If you have to keep the ordered option, there seems to be a workaround: make the relationship ordered both ways (thanks @Fabio Ritrovato).


回答2:

I'm also seeing this exact error on iOS 8 simulator and can't figure out what I'm doing wrong. I was able to work-around the issue by using @try/@catch but I'd rather understand where the conflict is or if I'm doing something wrong.

@Ryan - do you have the apple issue/link you could post here? What about the sample project?



回答3:

I saw the same issue and tried to apply the workaround mentioned by @knl. However, it seems that making the relationship ordered in both ways has a serious side-effect.

I noticed that if I adjusted the order of relationships in one entity, it will mess up the order of relations in other objects of the same entity.

Let's say we have two entities, Company and Employee. "Company" has a relationship "employees" to "Employee", which is an ordered to-many relationship. On the other hand, "Employee" has an inverse relationship to "Company" called "companies", which is also an ordered to-many relationship. (Initially Employee.companies was simply a to-many relationship, but later on I changed it to ordered to-many relationship as a workaround.)

Now, assuming there are two Company objects, A and B, I found that if I change the order of objects in A.employees, the order of objects in B.employees will be affected as well. I need to mention that A.employees was adjusted in a private child context and when the child context was saved and thus the changes were pushed back to the parent context, B.employees was altered then.

I added some logs and it seems that though the changes were made in A.employees only but it did trigger an global chain-effect. Core data integrated every object (X) in A.employees and removed all Company objects in X.companies and then added them back again in an arbitrary order, which caused the problem I am talking about.

I don't know if this is a bug in core data or an designed behavior. If this a bug then probably I need to report it to Apple but if this an designed behavior, what is another workaround?



回答4:

some nsstring append a nil value