TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SwiftData `isStoredInMemoryOnly: true` not working on macOS + iCloud?

Forums > SwiftUI

Wondering if anyone else is running into this.

It seems ModelConfiguration(isStoredInMemoryOnly: true) for previews (as outlined here) works correctly for

  • iOS + iCloud syncing
  • macOS WITHOUT iCloud syncing

But as soon as I turn on iCloud syncing capability for my macOS target, its as if the isStoredInMemoryOnly has no effect on the macOS target.

Here's my code...

I made a PreviewHelper to encapsulate the preview logic...

enum PreviewHelper {
    static let previewModelContainer: ModelContainer = {
        do {
            let config = ModelConfiguration(isStoredInMemoryOnly: true)
            let container = try ModelContainer(for: Task.self, configurations: config)
            return container
        } catch {
            fatalError("Failed to create model container for previewing: \(error.localizedDescription)")

And then use it like so...

#Preview {
    let container = PreviewHelper.previewModelContainer

    for task in MockData.tasks {

    return HorizonView()


On the macOS target & destination, using a macOS device in the Preview canvas, with iCloud syncing turned on that code inserts the MockData.tasks into my iCloud container every time the preview refreshes, so the data just keeps getting duplicated. With iCloud syncing turned off it behaves as expected/correctly (just inserting the MockData as needed for Previews).

In an iOS target, using the same helper and mock data, the helper behaves as expected/correctly (with or without iCloud syncing enabled).

Assuming this might be a bug/oversight with SwiftData and macOS? Or am I missing a needed configuration/capability on the macOS side? Anybody else seeing this?


FWIW, I also just tried running Paul's face facts app app with a macOS destination (after commenting out the bits that don't work on macOS), and the same behavior happens in previews.


Same here! A real issue!


I suggest you create a bug report on apple developer feedback as well.


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.