Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c RestKit对象映射失败,具体取决于属性名称_Objective C_Ios_Restkit - Fatal编程技术网

Objective c RestKit对象映射失败,具体取决于属性名称

Objective c RestKit对象映射失败,具体取决于属性名称,objective-c,ios,restkit,Objective C,Ios,Restkit,我看到RestKit和映射对象时出现了一些奇怪的行为。在我的目标对象中,如果我有一个名为“description”的NSString*属性,那么整个映射将失败。将其更改为任何其他名称或注释掉,一切都会成功。无论是否为属性设置了映射,都会发生这种情况,并且我可以在简单的测试类中重现它 服务器正在返回的JSON: { id = 1; name = item1; }, { id = 2; name = item2; } 我要映射到的对象SimpleObject

我看到RestKit和映射对象时出现了一些奇怪的行为。在我的目标对象中,如果我有一个名为“description”的NSString*属性,那么整个映射将失败。将其更改为任何其他名称或注释掉,一切都会成功。无论是否为属性设置了映射,都会发生这种情况,并且我可以在简单的测试类中重现它

服务器正在返回的JSON:

{
    id = 1;
    name = item1;
},
    {
    id = 2;
    name = item2;
}
我要映射到的对象SimpleObject.h。请注意,JSON中既没有描述,也没有不存在的属性,这意味着我认为这不是因为缺少“描述”:

#import <Foundation/Foundation.h>

@interface SimpleObject : NSObject

@property (nonatomic, assign) NSInteger identifier;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSString *nonexistant;

@end
我在AppDelegate中创建映射:

RKObjectManager *objectManager = [RKObjectManager managerWithBaseURLString:@"http://127.0.0.1/test"];

// Setup our object mappings
RKObjectMapping *testMapping = [RKObjectMapping mappingForClass:[SimpleObject class]];
[testMapping mapKeyPath:@"id" toAttribute:@"identifier"];
[testMapping mapKeyPath:@"name" toAttribute:@"name"];

 // Register our mappings with the provider using a resource path pattern 
[objectManager.mappingProvider setObjectMapping:testMapping forResourcePathPattern:@"/products"];
在我的didLoadObjects方法中,我有:

- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects
{
    NSLog(@"Loaded products: %@", objects);

    SimpleObject *obj = [objects objectAtIndex:0];
    NSLog(@"Loaded product ID %d -> Name: %@ ", obj.identifier, obj.name);
}
这将产生:

Finished performing object mapping. Results: {
    "" =     (
        (null),
        (null)
    );
}
如果我注释掉了description属性(但保留为nonexistant),那么一切都正常:

Finished performing object mapping. Results: {
    "" =     (
        "<SimpleObject: 0x8a4d040>",
        "<SimpleObject: 0x8a50130>"
    );
}
已完成对象映射。结果:{
"" =     (
"",
""
);
}

是否存在仅此属性名称的映射失败的原因?如果我将名称更改为“description”以外的任何名称,它也会成功

它与NSObject的描述属性冲突。重命名为other(如desc)。

谢谢,我不知道已经有description属性了。
Finished performing object mapping. Results: {
    "" =     (
        "<SimpleObject: 0x8a4d040>",
        "<SimpleObject: 0x8a50130>"
    );
}