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

SwiftData Listed Attributes

Forums > Swift

Hey All,

I had a shower thought for a project I'm working on, and can think of one method to accomplish this, but can't think of how to do it directly in SwiftData. I want to add a column in SwiftData that would allow for the user to select multiple, pre-filed items to exist in the value. I can think of how to do this on the UI side by creating a selectable list for the user to scroll through, but I'm wondering if there's a way to directly constrain this in the model iteslf. As I type this the obvious answer of creating an array property comes to mind but I haven't experimented with this in SwiftData. Does anyone have have any experience trying this out?

Thanks, Andy

   

@Obelix, so right now I have a property thats a string titled "description." What I realized was for this use case I could use a bool property to trigger whether or not to present a list of selectable defaults. For example:

@Model
class FlightActivity {
...
...
var isTraining: Bool
var description: // if isTraining { present options to choose from } options ["Steep Turns", "Touch and Go's", "Stall Recovery", etc...]

I could do this through the UI, but in later iterations I plan to sync this via JSON to a cloud service, and think it would be easier to constrain the model than the UI...

is this possible?

Thanks , Andy

   

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

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.