Domanda

I have following parent child relationship between two entites

enter image description here

In my scenario i have to update a parent attribute when some change occurs to child attribute.

    + (void)updateTaskStatus:(Task *)task
          withTaskStatus:(NSNumber *)taskStatus
  inManagedObjectContext:(NSManagedObjectContext *)context
{
    [task setValue:taskStatus forKey:@"taskCompletionStatus"];
    [task setValue:[NSNumber numberWithBool:NO] forKey:@"taskSyncStatus"];
    [task setValue:[NSNumber numberWithBool:NO] forKey:@"list.listSyncStatus"];
}

but this line from above method

[task setValue:[NSNumber numberWithBool:NO] forKey:@"list.listSyncStatus"];

produces following error

the entity Task is not key value coding-compliant for the key "list.listSyncStatus".'

So my question why is this happening? If this is not the way then what would be the proper way of doing that?

È stato utile?

Soluzione

"list.listSyncStatus" is not a key, but a key path (with two keys), therefore:

[task setValue:[NSNumber numberWithBool:NO] forKeyPath:@"list.listSyncStatus"];

Alternatively, use the property accessor methods and write

task.list.listSyncStatus = @NO;

if you have generated NSManagedObject subclasses for your entities.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top