Realm抛出RLMException,只有'object'属性可以是可选的,属性'name'是'string'类型

时间:2015-07-31 21:11:53

标签: realm

'RLMException', reason: 'Only 'object' properties can be made optional, and property 'name' is of type 'string'.'
    `First throw call stack:
    (
    0   CoreFoundation                      0x0000000102e01c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010496cbb7 objc_exception_throw + 45
    2   Realm                               0x00000001024f2fb6 +[RLMObjectSchema schemaForObjectClass:] + 5846
    3   Realm                               0x000000010257bcb6 +[RLMSchema initialize] + 1862
    4   libobjc.A.dylib                     0x000000010496d4d6 _class_initialize + 648
    5   libobjc.A.dylib                     0x00000001049766e1 lookUpImpOrForward + 351
    6   libobjc.A.dylib                     0x00000001049830d3 objc_msgSend + 211
    7   Realm                               0x0000000102555770 +[RLMRealm realmWithPath:key:readOnly:inMemory:dynamic:schema:error:] + 4800
    8   Realm                               0x0000000102554178 +[RLMRealm realmWithPath:readOnly:error:] + 152
    9   RealmSwift                          0x0000000102887e20 _TTOFCSo8RLMRealmCfMS_FT4pathSS8readOnlySb5errorGVSs33AutoreleasingUnsafeMutablePointerGSqCSo7NSError___GSqS__ + 112
    10  RealmSwift                          0x0000000102884af9 _TFC10RealmSwift5RealmcfMS0_FT4pathSS_S0_ + 105
    11  RealmSwift                          0x0000000102884c14 _TFC10RealmSwift5RealmCfMS0_FT4pathSS_S0_ + 100
    12  LocoPersist                         0x00000001021a030e _TFC11LocoPersist15PersistentStore8queryAllUSs9AnyObject_S_11IPersistent_US2___fGS0_Q_Q0__FT_GSaQ__ + 318
    13  LocoPersist                         0x00000001021a92c4 _TFFC11LocoPersist15PersistentStore8queryAllUSs9AnyObject_S_11IPersistent_US2___FGS0_Q_Q0__FFGSaQ__T_T_U_FT_T_ + 196
    14  LocoPersist                         0x00000001021a4527 _TTRXFo__dT__XFdCb__dT__ + 39
    15  libdispatch.dylib                   0x0000000105e00186 _dispatch_call_block_and_release + 12
    16  libdispatch.dylib                   0x0000000105e1f614 _dispatch_client_callout + 8
    17  libdispatch.dylib                   0x0000000105e066a7 _dispatch_queue_drain + 2176
    18  libdispatch.dylib                   0x0000000105e05cc0 _dispatch_queue_invoke + 235
    19  libdispatch.dylib                   0x0000000105e093b9 _dispatch_root_queue_drain + 1359
    20  libdispatch.dylib                   0x0000000105e0ab17 _dispatch_worker_thread3 + 111
    21  libsystem_pthread.dylib             0x000000010618c637 _pthread_wqthread + 729
    22  libsystem_pthread.dylib             0x000000010618a40d start_wqthread + 13
)
    libc++abi.dylib: terminating with uncaught exception of type NSException

1 个答案:

答案 0 :(得分:3)

看起来您正在尝试使用可选的字符串属性定义模型,但是作为异常状态,Realm不支持可选的字符串属性,只支持可选的对象属性。

您可以在此处详细了解Realm模型:https://realm.io/docs/swift/latest/#models