简体   繁体   中英

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.

您将需要将字符串作为专用参数传递,而不是像这样内置于格式字符串中:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM