1

我天真地尝试遵循使用 RestKit 0.20 映射我的 CoreData 类之一的指南

#import <RestKit/RestKit.h>
...
RKObjectMapping *mymap =
    [RKObjectMapping mappingForClass: NSClassFromString(@"MY_CLASS")];
[mymap mapAttributes:@"field1", @"field2", nil];

'RKObjectMapping' 没有可见的@interface 声明选择器'mapAttribute'

如果我键入[mymap map,我只会在完成列表中看到这两个函数

id mappingForDestinationKeyPath:(NSString *)
id mappingForSourceKeyPath:(NSString *)

我究竟做错了什么 ?


另一个例子,当我尝试使用共享RKObjectManager

[[RKObjectManager sharedManager].mappingProvider setMapping:map forKeyPath:@"/"];

找不到会员mappingProvider

4

2 回答 2

2

我认为这是 wiki 页面的问题,在文档(http://restkit.org/api/master/Classes/RKObjectMapping.htmlmapAttributes:中找不到。我认为 wiki 页面已过时,请改用此页面:https ://github.com/RestKit/RestKit/wiki/Object-MappingRKObjectMapping

您应该改用 addAttributeMappingsFromDictionary 方法:

[mymapp addAttributeMappingsFromDictionary:@{@"field1" : @"field1"}];

此外,mappingProvider 来自 0.20 之前的休息套件,并已被响应描述符(用于确定用于响应的映射的对象)替换

 RKResponseDescriptor *descriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:nil keyPath:@"key_path" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[[RKObjectManager sharedManager] addResponseDescriptor:descriptor];
于 2013-05-20T16:13:16.053 回答
0

像这样使用映射:

RKManagedObjectMapping * mymap = [RKManagedObjectMapping mappingForClass:[MY_CLASS class] inManagedObjectStore:self.objectStore];

    mymap.setDefaultValueForMissingAttributes = YES;
    mymap.primaryKeyAttribute = @"MY_CLASS_ID";
    mymap.rootKeyPath = @"ROOT_PATH_OF_SERVICE";
    [mymap mapKeyPathsToAttributes:
     @"WEB_SERVICE_ATTRIBUTE1", @"DATA_MODAL_ATTRIBUTE1",
     @"WEB_SERVICE_ATTRIBUTE2", @"DATA_MODAL_ATTRIBUTE2",
     @"WEB_SERVICE_ATTRIBUTE3", @"DATA_MODAL_ATTRIBUTE3",
     nil];
于 2013-05-21T04:51:51.053 回答