【问题标题】:Terminating app due to uncaught exception 'RLMException', reason: 'Invalid value '1973906' of type 'NSTaggedPointerString' for 'int' Realm由于未捕获的异常'RLMException'而终止应用程序,原因:'int'领域的'NSTaggedPointerString'类型的'无效值'1973906'
【发布时间】:2019-11-05 08:54:24
【问题描述】:

如果我将属性定义为字符串。

@Property NSString * value;

由于未捕获的异常“RLMException”而终止应用程序,原因: '字符串的'__NSCFNumber'类型的无效值'1993654'?'

或者如果定义为整数。

@Property NSInteger value;

由于未捕获的异常“RLMException”而终止应用程序,原因: 'int'的'NSTaggedPointerString'类型的无效值'1973906'

在这两种情况下应用都崩溃了。

崩溃报告。

*** Terminating app due to uncaught exception 'RLMException', reason: 'Invalid value '1973906' of type 'NSTaggedPointerString' for 'int?' property 'MMCase.Id'.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23b98bde __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff503b5b20 objc_exception_throw + 48
    2   Realm                               0x000000010ad75659 _Z17RLMThrowTypeErrorP11objc_objectP15RLMObjectSchemaP11RLMProperty + 617
    3   Realm                               0x000000010ad766bb _Z27RLMValidateValueForPropertyP11objc_objectP15RLMObjectSchemaP11RLMPropertyb + 3659
    4   Realm                               0x000000010ab63576 _ZN18RLMAccessorContext18value_for_propertyEP11objc_objectRKN5realm8PropertyEm + 214
    5   Realm                               0x000000010abd70af _ZN5realm6Object6createIU8__strongP11objc_object18RLMAccessorContextEES0_RT0_RKNSt3__110shared_ptrINS_5RealmEEERKNS_12ObjectSchemaET_bbmPNS_8BasicRowINS_5TableEEE + 431
    6   Realm                               0x000000010abd8595 RLMCreateObjectInRealmWithValue + 1477
    7   Realm                               0x000000010ab62c18 _ZN18RLMAccessorContext5unboxIN5realm12BasicRowExprINS1_5TableEEEEET_P11objc_objectbbbm + 296
    8   Realm                               0x000000010ab745cd _ZN5realm12_GLOBAL__N_112ValueUpdaterIU8__strongP11objc_object18RLMAccessorContextEclEPNS_12BasicRowExprINS_5TableEEE + 157
    9   Realm                               0x000000010ab735ef

【问题讨论】:

  • 您似乎混合了 Int & String。然后某些值对于一种情况或另一种情况无效。
  • 能否请您包含崩溃的代码并指出导致崩溃的特定行?实际上,您可能会尝试将无效或零数据存储到您的 var 中,这会导致崩溃。请花点时间查看How to create a Minimal, Complete, and Verifiable example

标签: ios objective-c realm


【解决方案1】:

您应该尝试改用NSNumber *value;。您在__NSCFNumber 发布的第一个异常中指出了这一点。从那里你可以使用任何一个

[value stringValue];

[value intValue];

要创建它,您可以使用范例:

value = [NSNumber numberWithInt: intValue];

【讨论】:

  • 我也尝试使用 NSNumber 和 NSNumber 异常 'RLMException',原因:'Property 'Id' 需要定义包含类型的协议 - 例如:NSNumber。'
  • 你能发布你使用 NSNumber 得到的崩溃吗?
  • 添加了有问题的崩溃报告。再次检查。
  • 你的代码中是否有 getId 或类似的东西?对于 MMCase 类
  • 那么您将不得不发布课程和使用它,因为仅通过提供的信息几乎不可能说出问题
【解决方案2】:

已通过使用 NSNumber 而不是 NSIntger 修复。

使用

@property NSNumber<RLMInt> *value

而不是

@Property NSInteger value;

取决于类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 2014-09-18
    • 2013-04-27
    • 2021-09-17
    相关资源
    最近更新 更多