SwiftData Document-based app produces strange write errors

I have a document app built using SwiftData because frankly I'm too lazy to learn how to use FileDocument. The app's title is "Artsheets," and I'm using a document type that my app owns: com.wannafedor4.ArtsheetsDoc. The exported type identifier has these values:

  • Description: Artsheets Document
  • Identifier: com.wannafedor4.ArtsheetsDoc
  • Conforms to: com.apple.package
  • Reference URL: (none)
  • Extensions: artsheets
  • MIME Types: (none)

And the code:

  • ArtsheetsApp.swift
import SwiftUI
import SwiftData

@main
struct ArtsheetsApp: App {
    var body: some Scene {
        DocumentGroup(editing: Sheet.self, contentType: .package) {
            EditorView()
        }
    }
}
  • Document.swift
import SwiftUI
import SwiftData
import UniformTypeIdentifiers

@Model
final class Sheet {
    var titleKey: String
    @Relationship(deleteRule: .cascade) var columns: [Column]
    init(titleKey: String, columns: [Column]) {
        self.titleKey = titleKey
        self.columns = columns
    }
}

@Model
final class Column: Identifiable {
    var titlekey: String
    var text: [String]
    init(titlekey: String, text: [String]) {
        self.titlekey = titlekey
        self.text = text
    }
}

extension UTType {
    static var artsheetsDoc = UTType(exportedAs: "com.wannafedor4.artsheetsDoc")
}

I compiling for my iPhone 13 works, but then when creating a document I get this error:

Failed to create document. Error: Error Domain=com.apple.DocumentManager Code=2 "No location available to save “Untitled”." UserInfo={NSLocalizedDescription=No location available to save “Untitled”., NSLocalizedRecoverySuggestion=Enable at least one location to be able to save documents.}
Answered by DTS Engineer in 802425022

it seems that the issue has been fixed. I tried with Xcode 16.0 beta 6 (16A5230g) + iPadOS 18.0 (22A5350a) and didn't see the issue happening.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Did you find a fix for this? I'm seeing the same thing...

Failed to create document. Error: Error Domain=com.apple.DocumentManager Code=2 "No location available to save “Untitled.myFile”." UserInfo={NSLocalizedDescription=No location available to save “Untitled.myFile”., NSLocalizedRecoverySuggestion=Enable at least one location to be able to save documents.}

I did not have that error before, but I get it now with the iOS 18 beta.

it seems that the issue has been fixed. I tried with Xcode 16.0 beta 6 (16A5230g) + iPadOS 18.0 (22A5350a) and didn't see the issue happening.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I can still see the issue, even on Xcode 16.0 beta 6. If I run the app on ios 16 or 17, all works. On iOS 18 I get this error.

@DTS Engineer the issue can be easily reproduced even on Apple's own sample code https://developer.apple.com/documentation/swiftui/building-a-document-based-app-with-swiftui, still present on Xcode 16 RC and corresponding iOS 18 simulator

The issue has not been fixed, at least I can easily reproduce it in Simulator

Yep, still happening in simulator too.

I found the issue for me: I had to be one macOS Sequoia for it to work on the simulator.

I have a similar issues running my app on simulator iOS 18.0. My app works fine on devices running ios17. I can't test on devices on iOS 18 just yet... (don't have access to such a device yet).

SwiftData Document-based app produces strange write errors
 
 
Q