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+

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and more!

Learn more here

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.