Why does my App freeze when declaring a State var of Type Date()?
I wanted to add a functionality to my App to store different Times (hour:minute) in an array of my SwiftData Model. And then to also add and remove items from this array. I ran into two problems.
SwiftData – delete all instances of model causes “Type cannot conform to PersistentModel” error
Warning If you don’t provide a predicate, the context will remove all
models of the specified type from the persistent storage.
SwiftData – delete all instances of model causes “Type cannot conform to PersistentModel” error
Warning If you don’t provide a predicate, the context will remove all
models of the specified type from the persistent storage.
How to filter a swiftdata query with multiple conditions?
static func GetCardsToLearnPredicate() -> Predicate<Card> { let todayMinus3Days: Date = Date.now.addDay(day: -3) let todayMinus7Days: Date = Date.now.addDay(day: -7) let todayMinus14Days: Date = Date.now.addDay(day: -14) let todayMinus30Days: Date = Date.now.addDay(day: -30) return #Predicate<Card> {card in card.box == 1 || (card.box == 2 && card.lastStatusChange >= todayMinus3Days) || (card.box == 3 && card.lastStatusChange >= todayMinus7Days) || (card.box […]
How to filter a swiftdata query with multiple conditions?
static func GetCardsToLearnPredicate() -> Predicate<Card> { let todayMinus3Days: Date = Date.now.addDay(day: -3) let todayMinus7Days: Date = Date.now.addDay(day: -7) let todayMinus14Days: Date = Date.now.addDay(day: -14) let todayMinus30Days: Date = Date.now.addDay(day: -30) return #Predicate<Card> {card in card.box == 1 || (card.box == 2 && card.lastStatusChange >= todayMinus3Days) || (card.box == 3 && card.lastStatusChange >= todayMinus7Days) || (card.box […]
String representation of SwiftData PersitentIdentifiers
Use case: I would like to associate subfolders stored in the Application Support Directory
on iOS with already saved instances of a SwiftData
entity type. If I had a way to represent the primary keys of the entities as a string, I could simply name these subfolders after the primary keys (without the need to generate e.g. random UUID folder names and persist these UUIDs as a field in the entity).
Why is SwiftData #Unique constraint working for following model?
I’m trying to restrict following model to “one per day”. It can reference 2 types of other structs (templet or preset) hence 2 different id’s. And it sets it’s creation day date to same one.
Proper way to fetch SwiftData models by id
I’m currently working on a simple read operation based on object IDs using SwiftData in my view model. I’m fetching data like this:
SwiftData unable to save Timer property of a class?
enter image description here