Post

Replies

Boosts

Views

Activity

Reply to Error in Xcode 15, beta 8
The API has changed since the WWDC videos. You need to add deleteRule: in front of cascade. class TodoList { var title: String @Relationship(deleteRule: .cascade) var items: [TodoItem] } This Developer doc on Switching from Core Data has the current syntax (Beta 8) https://developer.apple.com/documentation/coredata/adopting_swiftdata_for_a_core_data_app
Sep ’23
Reply to SwiftData won't work with Measurement types
I ran into the same issue. A work around I found is to use Measurement in an @Transient and convert it to a Double for storage. This lets me work with Measurements in my views, but stores it as a Double which SwiftData can handle. You want to store your data all as the same measurement system type (metric, US or UK) so you know what you're working with. I store everything in metric and then let the system convert it locale measurement system for display. If you have the user input measurement data, saving requires a little more work since you have to know what locale the user is in in order to do the correct conversion to metric for storage. Use @Environment(.locale) to get the user's measurement system and then use the built in measurement conversions to convert it to the storage unit. This post has a nice extension for getting the user Locale. https://stackoverflow.com/questions/50914297/get-value-of-localized-unit-from-measurement var widthMaxMeters: Double? = nil @Transient var widthMax: Measurement<UnitLength>? { get { if let widthMaxMeters { return Measurement<UnitLength>(value: widthMaxMeters, unit: .meters) } else { return nil } } set { widthMaxMeters = newValue?.value} }
Sep ’23