isStoredInMemoryOnly has no effect for macOS + iCloud?

Wondering if anyone else is running into this.

It seems ModelConfiguration(isStoredInMemoryOnly: true) for previews (as outlined by Paul Hudson / Hacking with Swift) 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 {
        container.mainContext.insert(task)
    }

    return HorizonView()
        .modelContainer(container)
        
}

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?

isStoredInMemoryOnly has no effect for macOS + iCloud?
 
 
Q