First, those aren't the same, the second should be:
myInstance.integerProperty = [NSNumber numbwerWithInt:2];
if integerProperty is an NSNumber.
IN general you use the second form when you are doing the most things. You use setVale:forKey and valueForKey: when you want to dynamically choose the property to store things in. For instance, think about how valueForKeyPath against an NSArray works (for reference, if you call -valueForKey: against an NSArray it will return an array where each object is the result of asking the corresponding object in that NSArray for that value:
- (NSArray *) valueForKey:(id)key {
NSMutableArray *retval = [NSMutableArray array];
for (NSObject *object in self) {
[retval addObject:[object valueForKey:key]];
}
return self;
}
In the above case we were able to use valueForKey to implement our function even though we do not know what the key is beforehand, since it is passed in as an argument.