dashbashrumble
dashbashrumble

Reputation: 251

Swift 2.1: Realm query fails with new line character

I am trying to query realm for an object with a filter condition and it keeps failing for strings with new line characters

results = realm.objects(LocalizedString).filter(filterString!)

Here filterString contains the string

"tuvEnglish = 'Ndjdj\n' AND tuvThai = 'Ndjdj\n'"

This fails with the error

'NSInvalidArgumentException', reason: 'Unable to parse the format string "tuvEnglish = 'Ndjdj
' AND tuvThai = 'Ndjdj
'"'

How should I fix this? Please help.

Upvotes: 1

Views: 244

Answers (1)

marius
marius

Reputation: 7806

You will need to pass the strings as dedicated arguments and not built-in to the format string like that:

 results = realm.objects(LocalizedString).filter("tuvEnglish = %@ AND tuvThai = %@", "Ndjdj\n", "Ndjdj\n")

Upvotes: 2

Related Questions