SwiftData History Tombstone Data is Unusable

After watching the WWDC video on the new history tracking in SwiftData, I started to update my app with this functionality. Unfortunately it seems that the current API in the first beta of Xcode 16 is rather useless in regards to tombstone data.

The docs state that it would be possible to get the data from the tombstone by using a keyPath, there is no API for this however. The only thing I can do is iterate over the values (of type any) without any key information, so I do not know which data is what.

Am I missing something or did we get a half finished implementation? There also does not seem to be any info on this in the release notes.

I have managed to get out the dictionary using reflection, guess this will do as a temporary workaround, but kind of strange that the api does not match the WWDC video or documentation.

For people running into the same thing, this works until the API is actually there (just do not use this in production):

extension History.Tombstone {
    subscript<T>(keyPath: KeyPath<Model, T>) -> T {
        let mirror = Mirror(reflecting: self)
        guard 
            let storageChild = mirror.children.first(where: { $0.label == "storage" }),
            let dictionary = storageChild.value as? [PartialKeyPath<Model> : Any],
            let value = dictionary[keyPath] as? T
        else {
            fatalError("Missing expected tombstone value for \(keyPath)")
        }
        
        return value
    }
}

The docs state that it would be possible to get the data from the tombstone by using a keyPath, there is no API for this however. The only thing I can do is iterate over the values (of type any) without any key information, so I do not know which data is what. Am I missing something or did we get a half finished implementation?

This is a known bug. If you have not filed a bug report for this issue, I encourage you to do so via Feedback Assistant. By filing a bug report, you’ll be able to track the issue and get notified of problem resolution.

SwiftData History Tombstone Data is Unusable
 
 
Q