【发布时间】:2015-01-02 18:39:18
【问题描述】:
当我从带有 null 属性的 restkit 创建一个对象时,应用程序崩溃说:
没有为属性“secondHeader”指定值或默认值 'FZPublication'
但是方法 defaultPropertyValues 有一个属性的默认值
+(NSDictionary *)defaultPropertyValues {
return @{
@"serviceId" : @0,
@"filterId" : @0,
@"proccessDate" : @"",
@"relation" : @"",
@"header" : @"",
@"text" : @"",
@"remoteId" : @0,
@"versionId" : @0,
@"footer" : @"",
@"secondHeader" : @"",
@"companyRemoteId" : @0,
};
}
我的 restkit 映射是:
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[FZPublication class]];
[mapping addAttributeMappingsFromDictionary:@{
@"IdServico":@"serviceId",
@"IdFiltro":@"filterId",
@"Lido":@"read",
@"DtProcessamento":@"proccessDate",
@"Relacao":@"relation",
@"Cabecalho1":@"header",
@"Cabecalho2":@"secondHeader",
@"Texto":@"text",
@"Id":@"remoteId",
@"IdEmpresa":@"companyRemoteId",
@"IdVersao":@"versionId",
@"DtPublicacao":@"publicationDateString",
@"NomeDiario" : @"diaryName",
@"DtDisponibilizacao" : @"availableDateString",
@"NDiario" : @"diaryNumber",
@"NProcesso" : @"proccessNumber",
@"NPagina" : @"pageNumber",
@"Rodape" : @"footer"
}];
有人知道发生了什么吗?
【问题讨论】:
-
设置一个异常断点,让它在崩溃时停止。发布该代码,以便我们可以看到它在做什么
-
能否也分享一下您的 RestKit 映射代码?
-
@Chris 异常断点在领域代码中停止,我只是保存在 restkit 回调中
-
RestKit 目前不知道如何在映射时考虑 RLMObject 的默认值。您必须确保没有 nil/null 值被手动映射。
标签: ios objective-c realm