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

Observing a Realm object? #38

Open
winstondu opened this issue Jul 17, 2020 · 4 comments
Open

Observing a Realm object? #38

winstondu opened this issue Jul 17, 2020 · 4 comments

Comments

@winstondu
Copy link

winstondu commented Jul 17, 2020

Hey @arturdev

This seems like an amazing library. However, one useful paradigm we use (with RxRealm) is the ability to observe changes on an object in the realm db and register a callback.

This function is the public func observe<T>(on queue: DispatchQueue? = nil, _ block: @escaping (RealmSwift.ObjectChange<T>) -> Void) -> RealmSwift.NotificationToken where T : RealmSwift.Object.

Does the fact that the objects are no longer "live" make this no longer possible?

@winstondu winstondu changed the title Realm object observing? Observing a Realm object? Jul 17, 2020
@arturdev
Copy link
Collaborator

Hi @winstondu. Unfortunately yes. The observing which you're looking for is done using ObjectiveC's KVO mechanism... And as you might already know, Swift native types don't support KVO

@winstondu
Copy link
Author

I see. But in your library, any write to the Realmable object will still be enclosed in a Realm.write no?

Is there no way to know whether the Realmable is updated (even if we don't know which properties are)?

@arturdev
Copy link
Collaborator

Yes, that is possible, but as you already mentioned, you will not know which property exactly was changed.

@winstondu
Copy link
Author

@arturdev , what would be the function when using this library to make change observations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants