Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DrakeRamoray

macrumors newbie
Original poster
Aug 8, 2012
1
0
Hi everyone.

I must to copy datas from my external database to core data and I have a little problem.
I use Json to communicate with iOS and it's work pretty well, each package of datas have an ID number.
I just want to save this datas in the iphone if the ID number is not saved yet on my IOS database.
How can I do?

Thank you
 
You might want to look at NSExpression. Something similar to:
Code:
NSExpression * expressionDescriptionCount = 
[NSExpression expressionForFunction:@"count:" 
arguments:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:@"IDnumber"]]];
[fetchRequest setResultType:NSDictionaryResultType];
 NSArray * results = [theContext executeFetchRequest:fetchRequest error:&error];
After the fetch went ok "results" will contain a dictionary.
If the value of the count key inside the dictionary is zero then your "id Number" is not yet present. Otherwise it will be the the nubmer of occurrence.

Ensure you match the string @"IDnumber" in expressionForKeyPath:mad:"IDnumber" with the correct spelling of the attribute.
 
You might want to look at NSExpression. Something similar to:
Code:
NSExpression * expressionDescriptionCount = 
[NSExpression expressionForFunction:@"count:" 
arguments:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:@"IDnumber"]]];
[fetchRequest setResultType:NSDictionaryResultType];
 NSArray * results = [theContext executeFetchRequest:fetchRequest error:&error];
After the fetch went ok "results" will contain a dictionary.
If the value of the count key inside the dictionary is zero then your "id Number" is not yet present. Otherwise it will be the the nubmer of occurrence.

Ensure you match the string @"IDnumber" in expressionForKeyPath:mad:"IDnumber" with the correct spelling of the attribute.


I don't understand the code you posted. You create an NSExpression object, and then you issue a fetch request that doesn't use the expression at all. Aren't you missing code that would add the expression to a predicate, and add the predicate to the fetch request? As written, the code uses an existing fetch request that has nothing to do with the expression object you created.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.