When should we use setValue:forKey:?


- (BNRItem *)createItem { BNRItem *p = [[BNRItem alloc] init]; double order; if ([allItems count] == 0) { order = 1.0; } else { order = [[allItems lastObject] orderingValue] + 1.0; } NSLog(@"Adding after %d items, order = %.2f", [allItems count], order); BNRItem *p = [NSEntityDescription insertNewObjectForEntityForName:@"BNRItem" inManagedObjectContext:context]; [b][p setOrderingValue:order];[/b] [allItems addObject:p]; return p; }

I am a little bit confused of when we should use the method setValue:forKey:

the book mentioned:
An NSManagedObject works a bit like a dictionary: it holds a key-value pair for every property (attribute or relationship) in the entity.

but in the above example, we were using [p setOrderingValue: order];

and I tried to do:
[p setValue: @“demo item” forKey: @“itemName”];

and it also worked, so is setValue: forKey: equivalent to the setter?

please advise