GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

SwiftData requires BackingData

Forums > SwiftUI

I am converting (re-implementing) an app to use SwiftData. Xcode is asking for BackingData when I create an instance of one of the SwiftData classes but I am coming up empty for an explanation of what this is and how to implement it properly. Any pointers? Original code snippet:

func addRace() {
        let racenum = races.count + 1
        let newRace = Race()
        newRace.raceNum = racenum
        ...

Which worked before SwifData. New code prompted by Xcode:

func addRace() {
        let racenum = races.count + 1
        let newRace = Race(backingData: <#BackingData<Race>#>)
        newRace.raceNum = racenum
        ...

3      

I have been able to work around this issue by initializing all the properties when creating the class instance. This did not work until I changed the enum property defaults from ".case" to "Type.case". Seems that is an XCode bug with enums and SwiftData.

4      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.