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.

4      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.