Swift 2.1: 领域查询失败并出现换行符

Swift 2.1: Realm query fails with new line character

我正在尝试在领域中查询具有过滤条件的对象,但对于包含换行符的字符串,它一直失败

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

此处 filterString 包含字符串

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

失败并出现错误

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

我应该如何解决这个问题?请帮忙。

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

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