LE SANG
LE SANG

Reputation: 11005

NSDiacriticInsensitivePredicateOption not supported by Realm

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.

Upvotes: 3

Views: 977

Answers (1)

bdash
bdash

Reputation: 18308

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.

Upvotes: 3

Related Questions