NSDirectory-->NSObject
[object setValuesForKeysWithDictionary:properties]
NSObject--> NSDirectory
NSDictionary *properties = [anObject dictionaryWithValuesForKeys:[anObject allKeys]];
注:
1、NSDirectory-->NSObject
可以封装一下(或者可以直接扩展到NSObject中):
// In your custom class + (id)customClassWithProperties:(NSDictionary *)properties { return [[[self alloc] initWithProperties:properties] autorelease]; } - (id)initWithProperties:(NSDictionary *)properties { if (self = [self init]) { [self setValuesForKeysWithDictionary:properties]; } return self; }