我正在将 RestKit 用于一个项目,我注意到类中不再有一个方法可以控制(elementToPropertyMappings)中的所有映射,因此我想知道放置新代码的最佳位置在哪里,目前我在在我的视图控制器中执行此操作,但我将在代码的其他区域中使用大多数相同的映射,因此是否有更有效的放置位置:
我指的代码是:
RKObjectMapping* userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping mapKeyPath:@"id" toAttribute:@"identifier"];
[userMapping mapKeyPath:@"forename" toAttribute:@"forename"];
[userMapping mapKeyPath:@"surname" toAttribute:@"surname"];
[userMapping mapKeyPath:@"email" toAttribute:@"email"];
[userMapping mapKeyPath:@"twitter_username" toAttribute:@"twitterUsername"];
[userMapping mapKeyPath:@"created" toAttribute:@"created"];
[userMapping mapKeyPath:@"use_gravatar" toAttribute:@"useGravatar"];
[userMapping mapKeyPath:@"avatar_url" toAttribute:@"avatarURL"];
[userMapping mapKeyPath:@"gender" toAttribute:@"gender"];
[[RKObjectManager sharedManager].mappingProvider setMapping:userMapping forKeyPath:@"user"];
如果这可以在 User 类的一个方法中,然后我可以调用它来设置这些映射等,那就太好了。
非常感谢