Post

Replies

Boosts

Views

Activity

Reply to SwiftData #Predicate case insensitive String comparison
Predicates only provide support for caseInsensitiveCompare(_:) when making case-insensitive string comparisons. This function returns a ComparisonResult, which has three cases: orderedAscending, orderedSame, and orderedDescending. To create a predicate that does a case-insensitive string comparison, you'll first need to create a constant defining the expected return value. This is because referring to an enum case using a keypath (e.g. ComparisonResult.orderedSame) is not supported in predicates. let orderedSame = ComparisonResult.orderedSame let predicate = #Predicate<Person> { person in person.name.caseInsensitiveCompare(name) == orderedSame }
Oct ’23