iOS Xcode 6:' RLMException',原因:' Realm从错误的线程访问'

时间:2015-01-26 00:23:55

标签: ios concurrency ios8 xcode6 realm

我遇到了Realm和并发问题。阅读Cocoa的文档,我不清楚RLMObjects不能跨线程共享,所以我遇到了一些线程错误,但现在当我在默认域上尝试甚至基本事务时,我收到一个异常。例如,这是我正在使用的唯一控制器:

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    RLMRealm *realm = [RLMRealm defaultRealm];
    [realm beginWriteTransaction];
    [realm commitWriteTransaction];
}

这是输出:

*** Terminating app due to uncaught exception 'RLMException', reason: 'Realm accessed from incorrect thread'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010ac83f35 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010a91cbb7 objc_exception_throw + 45
2   Key                                 0x0000000109b0cca1 _Z14RLMCheckThreadP8RLMRealm + 129
3   Key                                 0x0000000109b697bf -[RLMRealm beginWriteTransaction] + 47
4   Key                                 0x0000000109aafbe1 -[ViewController viewDidLoad] + 177
5   UIKit                               0x000000010b195a90 -[UIViewController loadViewIfRequired] + 738
6   UIKit                               0x000000010b195c8e -[UIViewController view] + 27
7   UIKit                               0x000000010b0b4ca9 -[UIWindow addRootViewControllerViewIfPossible] + 58

有没有其他人遇到并发和Realm的问题?我喜欢这个概念,但如果这仍然是一个问题,我可能不得不切换到FMDB。

0 个答案:

没有答案