core data - CoreData Using Sqlite and Unicode Strings Fetch Not Working -
i have application storing japanese text in coredata sqlite database. populating data seems work ok (as far can tell), when search on string field returns no records. if search on 1 of integer fields does.
the string data unicode (ie, japanese characters), question core data not work unicode? seems unlikely. special have done search (fetch) work?
code populate data looks this:
wordprogress *newwordprogress = [nsentitydescription insertnewobjectforentityforname:@"wordprogress" inmanagedobjectcontext:progresscontext]; newwordprogress.kanji = kanji; newwordprogress.kanji = kana; newwordprogress.senseindex = [nsnumber numberwithint:senseindex]; newwordprogress.skilltype = [nsnumber numberwithint:skilltype]; newwordprogress.leitnerdeck = leitnerdeck; newwordprogress.datelastshown = lastshowndate;
code test fetch, looks this:
nspredicate *pred = [nspredicate predicatewithformat:@"kanji = %@", @"彼"]; nsfetchrequest *testrequest = [[nsfetchrequest alloc] init]; [testrequest setpredicate:pred]; [testrequest setentity:[nsentitydescription entityforname:@"wordprogress" inmanagedobjectcontext:progresscontext]]; nsarray *results = [progresscontext executefetchrequest:testrequest error:&error];
but returns no records, when know records populated.
just tried too, , seems fail. i'm sure must doing fundamentally wrong:
wordprogress *newwordprogress = [nsentitydescription insertnewobjectforentityforname:@"wordprogress" inmanagedobjectcontext:progresscontext]; newwordprogress.kanji = @"彼"; newwordprogress.kanji = kana; newwordprogress.senseindex = [nsnumber numberwithint:senseindex]; newwordprogress.skilltype = [nsnumber numberwithint:skilltype]; newwordprogress.leitnerdeck = leitnerdeck; newwordprogress.datelastshown = lastshowndate; nspredicate *pred = [nspredicate predicatewithformat:@"kanji = %@", @"彼"]; nsfetchrequest *testrequest = [[nsfetchrequest alloc] init]; [testrequest setpredicate:pred]; [testrequest setentity:[nsentitydescription entityforname:@"wordprogress" inmanagedobjectcontext:progresscontext]]; nsarray *results = [progresscontext executefetchrequest:testrequest error:&error];
it's not unicode problem, it's nspredicate
error affect string. have:
nspredicate *pred = [nspredicate predicatewithformat:@"kanji = '%@'", @"彼"];
the single quotes in there problem. you're creating predicate looks literal %@
in data. single quotes prevent substituting @"彼"
%@
. take single quotes out , should work expected:
nspredicate *pred = [nspredicate predicatewithformat:@"kanji = %@", @"彼"];
Comments
Post a Comment