How to append data to a Model without UI in SwiftData?

I am creating an app, and on the app, the user can select something like, let's say, their workplace, while creating their account. I want to append the workplace data to a model without the use of UI, so that I can display the workplace names that the user can choose from. How do I append the data to the model?

Answered by Uasmel in 793481022

Do you already know all the workplace names or are they fetched from a server?

If you already have the names then you could simply create an enum that conforms to CaseIterable and then if you're using SwiftUI you would have a Picker that loops over allCases from which the user would pick from.

It would be helpful if you showed some code for your SwiftData models so we can provide more specific answers. It's not clear what data you're trying to persist and whether not a workplace is also a SwiftData model.

Accepted Answer

Do you already know all the workplace names or are they fetched from a server?

If you already have the names then you could simply create an enum that conforms to CaseIterable and then if you're using SwiftUI you would have a Picker that loops over allCases from which the user would pick from.

It would be helpful if you showed some code for your SwiftData models so we can provide more specific answers. It's not clear what data you're trying to persist and whether not a workplace is also a SwiftData model.

Y'all can ignore this post I've figured it out

How to append data to a Model without UI in SwiftData?
 
 
Q