Sharing SwiftData between two apps

This is probably super simple answer that I missed, but: I have an app that has a database; I'd like to create a second app (actually a CLI tool), and access the same database. Is that possible? And, if so, how? 😄

Answered by DTS Engineer in 871303022

Assuming that your second app is under the same team, you can create an app group container for the two apps to share, and then have your first app move its data store to the container, your second app should then be able to access the store.

To create an app group container, see Configuring app groups. To locate a SwiftData store to an app group container, see Share the same store file and the associate sample project.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Assuming that your second app is under the same team, you can create an app group container for the two apps to share, and then have your first app move its data store to the container, your second app should then be able to access the store.

To create an app group container, see Configuring app groups. To locate a SwiftData store to an app group container, see Share the same store file and the associate sample project.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Sharing SwiftData between two apps
 
 
Q