Core Data stack in #Playground

I'm using the #Playground macro in Xcode 26.0, running on macOS 26.0. I can get the basics working, but I don't understand how it hooks into the rest of the app, like the App Delete or the Core Data stack. Do we have to create a new Core Data stack, like for SwiftUI Previews, or can it hook into the stack from the main app (if so, how)?

Answered by DTS Engineer in 851553022

With the #Playground macro, you can use the symbols defined in other files, and so if you have something like Persistence.shared.persistentContainer that allow you to access the Core Data stack (NSPersistentContainer) globally, you can use it in your playground as well. Note that the operations with the same Core Data stack go to the same data store.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

With the #Playground macro, you can use the symbols defined in other files, and so if you have something like Persistence.shared.persistentContainer that allow you to access the Core Data stack (NSPersistentContainer) globally, you can use it in your playground as well. Note that the operations with the same Core Data stack go to the same data store.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Core Data stack in #Playground
 
 
Q