Just adding a little more detail...
Not surprising: Rather than calling context.refreshAllObjects() you could just call context.refresh(), passing in the object whose derived attribute you're about to access.
Surprising: Acquiring an object via an NSFetchRequest doesn't refresh its derived attributes.
(The second is surprising to me because I thought that an NSFetchRequest guaranteed a trip all the way to the store—which is, you might think, a kind of refresh.)
Fetching goes to the store to determine which objects match the request. It doesn't refresh the attributes unless you are using "shouldRefreshRefetchedObjects". And I've found that option doesn't actually work (FB6161838). Derived attributes are now documented here: https://developer.apple.com/documentation/coredata/nsderivedattributedescription
Can I ask you a favor? When I try to add more than one derived attribute to any entity, and then insert an object into that entity, I get a SIGABRT error with no reason. I have tried for an entire day to solve this.
I first create a new version of the
xcdatamodelwith two new attributes in Entity A. Each of those attributes is a boolean, and is set as
optional. Each references an
optionalboolean on Entity B. None of the attributes on either entity is set as
scalar. For each new derived attribute the derivation is basically a simple, to-one keypath to an object on Entity B. When I add just one of the new attributes - either one - the app functions fine. As soon as I add another attribute, the app crashes on inserting a new object into Entity A. Expanding on this, I find that adding more than one derived attribute at all to any entity is causing a crash upon inserting a new object into that entity.
The error is simply
Thread 1: signal SIGABRT
with no reason given.
This seems like crazy behavior to me. Is anyone else having an issue like this? Or do you have an idea of why I might be having this issue?