@quote:
has been dealing with CoreData recently. This is an IOS component with a large architecture and a steep learning curve, with a new understanding of each problem.
This time, just a little bit about the Fault problem caused by the erroneous cognition of the referential relationship between Object (Nsmanagedobject) and Context (Nsmanagedcontext).
used CoreData should have a most direct understanding of its basic use, that is: object is placed in the Context, the same time object will have a "managedobjectcontext" method, can get its Context.
Just beginning, I was very natural to think that Context strongly quoted Object. Object, in turn, also references the Context. Not really. The "managedobjectcontext" of Object is a method, not a property, which has no strong referential relationship.
If you create a new context from CoreData Stack, then take out an Object from the context. and assign this Object to a viewcontroller. Finally, in this viewcontroller, you will find a few tasks. Object becomes fault and cannot be used.
This is due to the assumption that the context is not the same, and after it is released, Object will cause "fault cannot be fulfilled" to be unusable due to the absence of this context.
About "fault cannot be fulfilled". Another example of Apple's official document "troubleshooting Core data" is not the same as the one I encountered. What it describes is: after removing the Object from the Context. The substance has been deleted. However, Object has not been released during the memory management cycle. Just become a Fault. If you visit this Object again, you will get "fault cannot be fulfilled" error.
Back to the problem I met, usually in a CoreData-based program that wasn't particularly complicated, and we wouldn't use a very multiple Context. And everyone's CoreData Stack has a strong reference to the Context at the appdelegate level. In particular, the temporary new Context is not used to forget the strong reference to it, so the problem is too uncommon.
In short, look at the document must be careful to distinguish between method and property, even with the same syntax + return is the same thing. Nor can they be considered one thing. From this point of view, it is still necessary to strictly use the syntax of [object method] and Object.property.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PS: I consulted the API documentation, which has not been understood in the following words:
|
-(BOOL) IsFault |
|
description |
Returns a Boolean value indicates whether the receiver is a fault. |
|
|
Knowing whether an object is a fault was useful in many situations when computations was optional. It can also is used to avoid growing the object graph unnecessarily (which may improve performance as it can avoid Time-co Nsuming fetches from data stores).
If This method is returns NO, then the receiver ' s data must is in memory. However, if this method returnsYES, it does isn't imply that the data was not in memory. The data may is in memory, or it may not, depending on many factors influencing caching
If the receiver is a fault, calling this method does does not cause it to fire. This sentence is really not clear? Also please enlighten the prawn @@ |
IOS Development Series: A way to coredata Object into Fault