Friday, September 12, 2025
HomeiOS Developmentios - How you can filter a swiftdata question with a number...

ios – How you can filter a swiftdata question with a number of circumstances?


static func GetCardsToLearnPredicate() -> Predicate {     
        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.field == 5 && card.lastStatusChange >= todayMinus30Days)
        
    }

I get the error: “The compiler is unable to type-check this expression in affordable time; attempt breaking apart the expression into distinct sub-expressions”

That’s the place the predicate is used:

@Question(filter: Card.GetCardsToLearnPredicate())
    var fetchedCards: [Card]

If I attempt to breaking it up into sub-expressions with some let’s then the compiler tells me, {that a} Predicate is barely allowed to have one line of expression.

I already excluded the date manipulation as a result of the compiler do not get it within the predicate.

I do not know what to do, additionally google would not helped me out. It could actually’t be the reality that I can not question information with only one or 2 expressions.

I am new within the iOS swift discipline, was working c# for years and within the OR-Mappers I used there, that was no drawback in any respect.

//edit
I attempted additionally the next model now:

return #Predicate ($0.field == 3 && $0.lastStatusChange >= todayMinus7Days) 

error once more: the compiler is unable to type-check this expression in affordable time; attempt breaking apart the expression into distinct sub-expressions

return #Predicate ($0.field == 2 && $0.lastStatusChange >= todayMinus3Days)
        

This does not throw an exception so 2 expressions appears to be quick sufficient, however how can I add the opposite expressions? I would like them in it 😀

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments