Tuesday 15 June 2010

ios - Writing an NSPredicate for 'CONTAINED_BY' text query -



ios - Writing an NSPredicate for 'CONTAINED_BY' text query -

i trying build query of core info store retrieves entity's attribute values when occur in longer string;

i.e, instead of seeking instances attribute value contains (shorter) string :

request.predicate = [nspredicate predicatewithformat:@"carbrand contains[c] 'merced'"]

i want find instances (of entity) attribute values found 'contained in' arbitrary (longer) string :

nsstring* textstring = @"elaine used drive audis, owns mercedes"; request.predicate = [nspredicate predicatewithformat:@"%@ contains[c] carbrand", textstring ];

(ie. retrieve array holding objects carbrand = @"audi" , carbrand = @"mercedes")

in attempts, nspredicate doesn't seem expressions attribute name on right hand side , throws error...

[__nscfconstantstring countbyenumeratingwithstate:objects:count:]: unrecognized selector sent instance 0x

...is there way of constructing such query attribute name on left hand side - 'contained_by' query, were?

ps. searching so, i've found solutions splitting text component words which, in scenario, less ideal! type of approach that's viable?

build regex string array , utilize matches in predicate.

[nspredicate predicatewithformat:@"%@ matches '*(audi|mercedes)*'", teststring];

to filter cars based on brand:

nsarray *brands = [@"audi", @"mercedes"]; [nsprediate predicatewithformat:@"carbrand in %@", brands];

ios objective-c osx core-data nspredicate

No comments:

Post a Comment