Post

Replies

Boosts

Views

Activity

Reply to Core Data WWDC 2020 FAQ
Set in Swift is an immutable value type. We do not recommend making Core Data relationships typed this way despite the obvious convenience. Core Data makes heavy use of Futures, especially for relationship values. These are reference types expressed as NSSet. The concrete instance is a future subclass however. This lets us optimize memory and performance across your object graph. Declaring an accessor as Set forces an immediate copy of the entire relationship so it can be an immutable Swift Set. This loads the entire relationship up front and fulfills the Future all the time, immediately. You probably do not want that. In my opinion, it is unfortunate this is "documented" here. The internet is full of guidance counter to this and to have it hidden as a post in a developer forum is sub-optimal. I stumbled upon this guidance by accident while looking for something else. More over, if this really is true the idea that a better "batteries included" reference type that conforms to Swift's Collection is not provided in Core Data this many years after Swift came on the scene is unfortunate especially since Core Data is Apple's hallmark framework for application developers who desire to persist their users' data in a robust and feature-rich way.
Jun ’21