I am working on a simple comparison of two lists to see which items in the grades list are in the larger โtargetโ list. I get data on the fly by analyzing two CSV files and saving everything as strings. I successfully import data into a data warehouse and I can get a list of objects without problems.
The problem arises when I actually perform a search. In fact, I am looking for short 1234-5 in the form 1234 from the scoring list in the target list, which are presented in the form 1234-5 . The predicate that I use, I use the CONTAINS comparison in the form [NSString stringWithFormat:@"%@ CONTAINS %@", kOC_Target_PrintBookCode, evalIsbn]
The error I get is the following: (grabbed by my NSLog )
NSInvalidArgumentException: Can't look for value (1494) in string (49885); value is not a string
I get the impression that although the ISBN is read from NSString and has a data point specified as String in the main data store, Core Data still does something in the background with a value for whatever reason it considers necessary. Any ideas?
Here is the relevant logic of the process (although I use this term doubtfully). Unless otherwise specified in the code, all values โโthat are controlled and / or stored are NSString :
NSArray *evalBooks = [self getEntitiesByName:kOC_EntityName_EvalBook usingPredicateValue:[NSString stringWithFormat:@"%@ > \"\"", kOC_Eval_Bookcode] withSubstitutionVariables:nil inModel:[self managedObjectModel] andContext:[self managedObjectContext] sortByAttribute:nil]; if ( ( !evalBooks ) || ( [evalBooks count] == 0 ) ) { // we have problem NSLog(@"( !evalBooks ) || ( [evalBooks count] == 0 )"); return; } [evalBooks retain]; int firstEvalBook = 0; int thisEvalBook = firstEvalBook; int lastEvalBook = [evalBooks count]; NSLog(@"lastEvalBook: %i", lastEvalBook); for (thisEvalBook = firstEvalBook; thisEvalBook < lastEvalBook; thisEvalBook++) { NSManagedObject *evalBook = [[evalBooks objectAtIndex:thisEvalBook] retain]; NSString *rawIsbn = [[evalBook valueForKey:kOC_Eval_Bookcode] retain]; NSString *isbnRoot = [[self getIsbnRootFromIsbn:rawIsbn] retain]; // this is a custom method I created and use elsewhere without any issues. NSArray *foundBooks = [self getEntitiesByName:kOC_EntityName_TargetBook usingPredicateValue:[NSString stringWithFormat:@"%@ CONTAINS %@", kOC_Target_PrintBookCode, isbnRoot] withSubstitutionVariables:nil inModel:[self managedObjectModel] andContext:[self managedObjectContext] sortByAttribute:kOC_Target_PrintBookCode]; if ( foundBooks != nil ) { [foundBooks retain]; NSLog(@"foundBooks: %lu", [foundBooks count]); } else { }
source share