SwiftData in appleOS 27
Section your query results by creating your query with a macro that takes a
sectionByparameter, as listed on the Additional query macros page.Use types that conform to
Codablein a model, including types you donβt control directly, by using thecodableoption forSchema.Attribute.Receive real-time updates to models that match specified fetch criteria by using the
ResultsObservertype.Observe remote model changes with the
HistoryObservertype.
Discover the latest enhancements to SwiftData. Weβll show you how to persist custom and third-party types using
Codable, and group fetched data into sections in your SwiftUI app. Weβll also explore how to observe data store changes anywhere else usingResultsObserverandHistoryObserver, giving you the flexibility to drive powerful state objects and react precisely to model updates.
Again, there seems to be nothing new in Core Data this year, nor any communication about it. Thereβs still no interoperability for object IDs. The SwiftData changes seem fine but donβt really address the new frameworkβs deficiencies relative to Core Data. It seems like there are still basic problems with threading. I just donβt understand how Apple is deciding what to prioritize with this framework.
With SwiftUI, the bones seem questionable, but at least we can see that Apple is full steam ahead, with substantial progress to address limitations and pain points. SwiftData seemed to have better bones and is much less ambitious. Getting it right seemed like just a matter of follow through. But, for some inexplicable reason, it seems to lack the resources and/or urgency to reach its potential. And even though SwiftUI is clearly the chosen one, AppKit remains in development. Meanwhile, Core Data seems to be abandoned, even though SwiftData feels more like a side quest than a genuine attempt to supplant it.
The implicit message, for those who have build the core of their app on top of Appleβs old persistence framework, seems to be that Apple is not looking out for their needs. Core Data will surely get maintenance to the extent that Appleβs own apps need it, but thereβs no evidence of a future or even a migration plan. The answer, I guess, is third-party frameworks, but thatβs not an easy migration, either, since none is even as close a match as SwiftData.
Add persistence with SwiftData:
Experience SwiftData in action as we add persistence to an existing app. Weβll show you how to define your data models and seamlessly integrate persistent data with SwiftUI. Youβll also learn foundational skills for managing your appβs state using this expressive, declarative API.
Join us online for a deep dive into WWDC26 with Apple engineers and designers to ask questions, get advice, and follow the discussion about the weekβs biggest SwiftData announcements.
macOS Golden Gate 27 Beta Release Notes:
Fixed: You might experience a deadlock for
@Querywhen saving aModelContexton a background actor while scheduling new async tasks for aModelActor.
I am so pleased to say these words: IT IS A BIG YEAR FOR SWIFTDATA! π
SwiftData predicates can now work directly with enum values, resulting in cleaner models and simpler query code.
[β¦]
In iOS 27, Apple introduced support for compound predicates through the
Predicate(all:)andPredicate(any:)initializers, making it easier to build queries dynamically based on user input.
Iβm not sure why that took so long.
The framework is gradually moving beyond simple demos and becoming easier to use in larger, more sophisticated projects.
[β¦]
iOS 27 is the first release where many of the frameworkβs early rough edges have started to disappear.
Results of my now-yearly check to see if SwiftDataβs
ModelActorcontinues to sometimes run code on the main thread: yes it does
Compared with
@Querygaining support for section fetches, andResultsObserverenabling observation of query result changes outside views, I am more interested in@Attribute(.codable). It provides a clearer storage intent and gives developers a way to avoid falling into the black box of composition.Of course,
@Attribute(.codable)is not a silver bullet. It is more like a clearly defined escape hatch SwiftData provides for opaqueCodabletypes: suitable for storing external types that you cannot model yourself, but still genuinely need to persist. The cost is that this content cannot participate in SwiftDataβs predicate, sort, or migration awareness. Precisely for this reason, its value lies not in being βmore powerful,β but in being βmore explicit.βHowever, SwiftData still does not provide cloud syncing for public / shared data, nor have I seen a clearer signal of performance improvements. These issues will continue to limit its adoption. For many developers, SwiftData this year feels more like it is filling key gaps rather than making a leap significant enough to fundamentally change confidence in it.
Codabletypes in SwiftData seem pretty lame given that SQLite absolutely does have JSON support and does support queries on it?But the funnier thing in the MKMapItem.Identifier example is that
MKMapItem.Identifieris aRawRepresentable==String, so it could actually be stored as aStringin the store.
Previously: