I have already searched for answers and whatever I tried unfortunately did not work.
My case is as follows:
I have an array of keywords and I am building an NSPredicate
in order to filter data from CoreData. The code below:
var strKeywordsOrFilter = "(1 == 1)" //just an initial {true} statement to assist with the OR conditional
for intIndex in 0...pInputWords.count - 1
{
let strKeyword = "'" + pInputWords[intIndex] + "'"
strKeywordsOrFilter = strKeywordsOrFilter + " OR (imageDescr CONTAINS[c] " + strKeyword + ")"
}
imageDescr
is one of the entity attributes in my CoreData.
What I want to accomplish is to create a concatenated string of OR conditions for as many keywords exist in the array pInputWords
.
When I debug print the variable strKeywordsOrFilter
it does NOT contain any backslashes before any single quote character, e.g.
(1 == 1) OR (imageDescr CONTAINS[c] 'camping') OR (imageDescr CONTAINS[c] 'lake')
but the same variable when it reaches the "predicate" command, it contains backslashes before every single quote, e.g.
(1 == 1) OR (imageDescr CONTAINS[c] 'camping') OR (imageDescr CONTAINS[c] 'lake')
I have tried a number of workarounds but nothing seems to get rid of the "".
Any help would be appreciated because I am really stuck!
question from:
https://stackoverflow.com/questions/65856362/swift-is-there-a-way-to-include-single-quotes-in-a-concatenated-string 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…