TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.