【问题标题】:Realm default value property crashes领域默认值属性崩溃
【发布时间】: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


【解决方案1】:

您如何在 Realm 中创建和存储该对象?请记住,您不能在 Realm 中保存任何具有 null 值的属性,因为它总是会崩溃。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多