Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Can only add notification blocks from within runloops.' #11

Closed
lamson-dev opened this issue May 4, 2016 · 10 comments
Closed

'Can only add notification blocks from within runloops.' #11

lamson-dev opened this issue May 4, 2016 · 10 comments

Comments

@lamson-dev
Copy link

I'm getting this exception in my app, not sure how I get it to this state...
Posting an issue/question here to see if anyone has the same issue.

*** Terminating app due to uncaught exception 'RLMException', reason: 'Can only add notification blocks from within runloops.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001112bad85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000110d2edeb objc_exception_throw + 48
2 Realm 0x000000010fce9627 -[RLMRealm addNotificationBlock:] + 0
3 Realm 0x000000010fcef970 -[RLMResults addNotificationBlock:] + 46
4 RealmSwift 0x00000001100ef4c3 _TFC10RealmSwift7Results20addNotificationBlockfFGOS_21RealmCollectionChangeGS0_x__T_CSo20RLMNotificationToken + 243
5 ApptioMobileSwift 0x000000010f79f962 _TTWuRxC10RealmSwift6ObjectrGCS_7Resultsx_17ApptioMobileSwift19NotificationEmitterS2_FS3_20addNotificationBlockfFGOS_21RealmCollectionChangex_T_CSo20RLMNotificationToken + 130
6 ApptioMobileSwift 0x000000010f7a43a1 TFFe17ApptioMobileSwiftRxS_19NotificationEmitterx10RealmSwift19RealmCollectionTyperS0_12asObservableFT_GC7RxSwift10Observablex_U_FGVS3_11AnyObserverQPS0__PS3_10Disposable + 1137
7 ApptioMobileSwift 0x000000010f7a059d TPA__TFFe17ApptioMobileSwiftRxS_19NotificationEmitterx10RealmSwift19RealmCollectionTyperS0_12asObservableFT_GC7RxSwift10Observablex_U_FGVS3_11AnyObserverQPS0__PS3_10Disposable + 1005

@lamson-dev
Copy link
Author

Figured it out. Thanks.

@icanzilb
Copy link
Member

icanzilb commented May 5, 2016

👍

@superlopuh
Copy link

:/ I'm having a problem with this now, and I'm not sure how to solve it. Could you post your fix, please?

@icanzilb
Copy link
Member

Unfortunately there's nothing more to the exception "Can only add notification blocks from within runloops." than it already says. There is no fix for this, you need to subscribe for notifications from a thread with a runloop

@superlopuh
Copy link

Ah. Where can I read up on runloops? I've never seen this before.

@icanzilb
Copy link
Member

Your main thread has one installed by default, and your newly spawned background threads don't. You can read more here: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html

@superlopuh
Copy link

superlopuh commented Jun 23, 2016

I'll read that, thank you! Is there a reason that runloops aren't handled inside the asObservable() method?

@icanzilb
Copy link
Member

This is a limitation of Realm, it hasn't anything to do with the rx extension. RxRealm observes your realm on the thread you subscribe on so it's up to you to do it on the main thread or have a runloop running

@icanzilb
Copy link
Member

If you'd like to read a complete post about reading/writing from different threads have a look here: https://realm.io/news/marin-todorov-realm-rxswift/

@superlopuh
Copy link

Epic! Thank you

@RxSwiftCommunity RxSwiftCommunity locked and limited conversation to collaborators Jun 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants