NSDiacriticInsensitivePredicateOption not supported by Realm

点点圈 提交于 2019-12-02 01:30:53

问题


I have DictObject with a text property that contains some Vietnamese letters, such as "Sống".

@interface DictObj : RLMObject
@property NSString *text;//Ex: sống
@end

I would like to use BEGINSWITH[cd] to perform a diacritic insensitive search, but Realm does not currently support it:

RLMResults *fetchedResults = [DictObj objectsInRealm:realm where:@"text BEGINSWITH[cd] %@",inputText];

I can use kCFStringTransformStripDiacritics to transform my input text, but I don't know how to perform that string transformation when the string is already stored in Realm file.


回答1:


Realm Objective-C v2.5.0 added support for the diacritic-insensitive modifier on most string operations. All supported string comparison operators except LIKE now support the [d] modifier.

Note that there is a performance tradeoff in performing a diacritic-insensitive comparison. If you're doing very frequent lookups it may be preferable to pre-compute a version of the string with the diacritics stripped and store it in a second property on your model. You could then use the diacritic-free property in queries, while continuing to use the original property for display purposes. If you have existing data stored in your Realm, you can add the extra property to your class and populate it for existing objects within a migration.



来源:https://stackoverflow.com/questions/33760078/nsdiacriticinsensitivepredicateoption-not-supported-by-realm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!