swift - How to pass the same parameter multiple times in CoreData iOS predicate builder? -
i have uitableview
uisearchbar
let me filter data based on search text
uisearchbar
.
the coredata
table contains 3 attributes
name, notes, date
i want search 3 columns occurrence based on user
search text.
so tried on:
let searchtext = searchtext.lowercased() let query = "name contains[cd] %@ or notes contains[cd] %@ or date contains[cd] %@" let predicate = nspredicate(format: query, searchtext, searchtext, searchtext)
is there way pass same parameter (searchtext
) 1 time?
something java
string formatter:
let query = "name contains[cd] %1$@ or notes contains[cd] %1$@ or date contains[cd] %1$@" let predicate = nspredicate(format: query, searchtext)
you can use substitution variables:
let searchtext = searchtext.lowercased() let template = nspredicate(format: "name contains[cd] $srch or notes contains[cd] $srch or date contains[cd] $srch") let subvars = ["srch": searchtext] let predicate = template.withsubstitutionvariables(subvars)
see "creating predicates using predicate templates" in apple documentation.
Comments
Post a Comment