UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

3      

Hacking with Swift is sponsored by Superwall

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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

Reply to this topic…

You need to create an account or log in to reply.

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.