Post

Replies

Boosts

Views

Activity

Reply to SwiftData superclass prevents usage of ID
@DTS Engineer Thanks a lot for providing the sample, I have tested it out in the sample project and it does work. It works as expected when contained inside a SwiftUI View. To narrow the problem down it seems that the issue stems from superclass model ID being used inside an @Observable macro object. For context I have a @Observable object NavigationStore that contains state related to navigation such as selection. When specifying an array of Asset.ID inside that I get aforementioned error 'ID' is inaccessible due to '@_spi' protection level. Expanding the macro another error is given, Cannot yield reference to storage of type 'Set<Asset.ID>' (aka 'Set<PersistentIdentifier>') as an inout yield of type '<<error type>>'. To reproduce you can use this code block: @MainActor @Observable public final class NavigationStore { // MARK: - Selection var assetSelection: Set<Asset.ID> = [] } @Model public class Asset { // MARK: - Properties var name: String = "" } @available(macOS 26.0, *) @Model public class ImageAsset: Asset { // MARK: - Properties var imageName: String = "image" } @main struct MyApp: App { @State private var navigationStore: NavigationStore = NavigationStore() var body: some Scene { WindowGroup { Text("Hello World!") } .modelContainer( for: [ AssetGroup.self, Asset.self, ColorAsset.self, ImageAsset.self, SymbolAsset.self ], isUndoEnabled: true ) } Thanks again for taking the time!
Jun ’25
Reply to SwiftData superclass prevents usage of ID
Not exactly sure what you mean with proper relationship, could you elaborate here? Using [Asset] will prevent the .dragContainer modifier from working to my understanding, as it expects a transferable item type and likewise an array of the Item.ID that matches the item type for selection. https://developer.apple.com/documentation/swiftui/view/dragcontainer(for:in:selection:_:)
Jun ’25
Reply to TestFlight build crashes from fetch descriptor
FB22393059 feedback assistant ID
Replies
Boosts
Views
Activity
2w
Reply to TestFlight build crashes from fetch descriptor
Refactoring fetchDescriptor to work as a fetch descriptor for Asset instead solved the crash static func fetchDescriptor(nameStartingWith prefix: String) -> FetchDescriptor<Asset> { let predicate = #Predicate<Asset> { asset in asset.name.starts(with: prefix) } return FetchDescriptor<Asset>(predicate: predicate) }```
Replies
Boosts
Views
Activity
Mar ’26
Reply to SwiftData superclass prevents usage of ID
Changing the name from Asset to anything else solved the issue for me.
Replies
Boosts
Views
Activity
Jun ’25
Reply to SwiftData superclass prevents usage of ID
@DTS Engineer Thanks a lot for providing the sample, I have tested it out in the sample project and it does work. It works as expected when contained inside a SwiftUI View. To narrow the problem down it seems that the issue stems from superclass model ID being used inside an @Observable macro object. For context I have a @Observable object NavigationStore that contains state related to navigation such as selection. When specifying an array of Asset.ID inside that I get aforementioned error 'ID' is inaccessible due to '@_spi' protection level. Expanding the macro another error is given, Cannot yield reference to storage of type 'Set<Asset.ID>' (aka 'Set<PersistentIdentifier>') as an inout yield of type '<<error type>>'. To reproduce you can use this code block: @MainActor @Observable public final class NavigationStore { // MARK: - Selection var assetSelection: Set<Asset.ID> = [] } @Model public class Asset { // MARK: - Properties var name: String = "" } @available(macOS 26.0, *) @Model public class ImageAsset: Asset { // MARK: - Properties var imageName: String = "image" } @main struct MyApp: App { @State private var navigationStore: NavigationStore = NavigationStore() var body: some Scene { WindowGroup { Text("Hello World!") } .modelContainer( for: [ AssetGroup.self, Asset.self, ColorAsset.self, ImageAsset.self, SymbolAsset.self ], isUndoEnabled: true ) } Thanks again for taking the time!
Replies
Boosts
Views
Activity
Jun ’25
Reply to SwiftData superclass prevents usage of ID
Not exactly sure what you mean with proper relationship, could you elaborate here? Using [Asset] will prevent the .dragContainer modifier from working to my understanding, as it expects a transferable item type and likewise an array of the Item.ID that matches the item type for selection. https://developer.apple.com/documentation/swiftui/view/dragcontainer(for:in:selection:_:)
Replies
Boosts
Views
Activity
Jun ’25
Reply to SwiftData superclass prevents usage of ID
Feedback Assistant ID: FB18054420
Replies
Boosts
Views
Activity
Jun ’25