Does the listing have master data in the background?

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 { } 
+4
source share
2 answers

If you build your predicate as an NSString , I consider

 [NSString stringWithFormat:@"%@ CONTAINS %@", kOC_Target_PrintBookCode, isbnRoot] 

it should be

 [NSString stringWithFormat:@"%@ CONTAINS '%@'", kOC_Target_PrintBookCode, isbnRoot] 

It seems that you are confusing how predicateWithFormat: works with how stringWithFormat: works.

+3
source

Presumably, either kOC_Target_PrintBookCode or isbnRoot not an object that can be converted to a string. For instance. if it is an integer, the %@ operator cannot convert an integer to a string value.

0
source

Source: https://habr.com/ru/post/1347594/


All Articles