【问题标题】:App is crashing when I call defaultRealm当我调用 defaultRealm 时应用程序崩溃
【发布时间】:2015-07-29 18:01:48
【问题描述】:

我正在尝试删除 RLMObject 子类的每个实例,每当我调用 [Realm defaultRealm] 时,我的应用程序就会崩溃。这是我在控制台中不断得到的内容。我正在使用 cocoapods,版本 0.93.2

*** Terminating app due to uncaught exception 'RLMException', reason: 'Can't persist property 'Id' with incompatible type. Add to ignoredPropertyNames: method to ignore.'
*** First throw call stack:
(
0   CoreFoundation                      0x0000000106b15c65 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x00000001067aebb7 objc_exception_throw + 45
2   business_sect                       0x000000010206251b -[RLMProperty initWithName:indexed:property:] + 571
3   business_sect                       0x00000001020511c1 +[RLMObjectSchema propertiesForClass:isSwift:] + 1457
4   business_sect                       0x000000010204fa5c +[RLMObjectSchema schemaForObjectClass:] + 812
5   business_sect                       0x00000001020c4d06 +[RLMSchema initialize] + 1862
6   libobjc.A.dylib                     0x00000001067af4d6 _class_initialize + 648
7   libobjc.A.dylib                     0x00000001067b86e1 lookUpImpOrForward + 351
8   libobjc.A.dylib                     0x00000001067c50d3 objc_msgSend + 211
9   business_sect                       0x00000001020aa34d +[RLMRealm realmWithPath:key:readOnly:inMemory:dynamic:schema:error:] + 4765
10  business_sect                       0x00000001020a8d78 +[RLMRealm realmWithPath:readOnly:error:] + 152
11  business_sect                       0x00000001020a8bdf +[RLMRealm defaultRealm] + 111
12  business_sect                       0x0000000101f386ff __40-[CGCUserManager signInUser:completion:]_block_invoke + 879
13  business_sect                       0x0000000101fd39d8 __64-[AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke46 + 40
14  libdispatch.dylib                   0x0000000107095186 _dispatch_call_block_and_release + 12
15  libdispatch.dylib                   0x00000001070b4614 _dispatch_client_callout + 8
16  libdispatch.dylib                   0x000000010709ca1c _dispatch_main_queue_callback_4CF + 1664
17  CoreFoundation                      0x0000000106a7d1f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
18  CoreFoundation                      0x0000000106a3edcb __CFRunLoopRun + 2043
19  CoreFoundation                      0x0000000106a3e366 CFRunLoopRunSpecific + 470
20  GraphicsServices                    0x0000000107d63a3e GSEventRunModal + 161
21  UIKit                               0x0000000104e6d8c0 UIApplicationMain + 1282
22  business_sect                       0x0000000101f6927f main + 111
23  libdyld.dylib                       0x00000001070e8145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

编辑:我也在 iphone6 模拟器上进行测试

这里是 RLMObject 子类:

#import "RLMObject.h"

@interface CGCUser : RLMObject
@property NSString *EmailAddress;
@property BOOL IsActive;

@end

还有第二个对象

@interface CGCCardInfo : RLMObject
@property NSInteger *Id;
@property NSString *nickName;
@property NSString *token;
@property NSString *displayNumber;
@property BOOL *isDefault;
@property NSString *cardType;
@end
RLM_ARRAY_TYPE(CGCCardInfo)

【问题讨论】:

  • 你能分享你的RLMObject子类定义吗?
  • 没关系,我想我想通了

标签: ios objective-c persistence cocoapods realm


【解决方案1】:

问题出在@property BOOL *isDefault;这一行

如果您将其更改为 @property BOOL isDefault;,它应该完全符合您的要求!

【讨论】:

  • 是的,我在编辑后注意到了它 lol 这同样适用于NSInteger *Id
【解决方案2】:

同样的事情发生在我身上。

@property NSInteger *Id 是这里有问题的字段。您使用指向NSInteger 的指针而不是NSInteger 本身。

解决办法是直接替换成引用:@property NSInteger Id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-03
    • 1970-01-01
    • 2017-05-22
    • 2018-04-27
    • 2022-12-12
    • 2019-10-12
    • 2016-06-20
    • 2018-07-23
    相关资源
    最近更新 更多