crash on coredata ios8

后端 未结 4 1005
不知归路
不知归路 2021-02-12 12:32

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\         


        
4条回答
  •  北海茫月
    2021-02-12 12:54

    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?

提交回复
热议问题