update my core data database

Discussion in 'iOS Programming' started by DrakeRamoray, Aug 8, 2012.

  1. macrumors newbie

    Joined:
    Aug 8, 2012
    #1
    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
     
  2. macrumors regular

    Joined:
    Aug 28, 2008
    #2
    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.
     
  3. macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #3

    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.
     

Share This Page