-
Notifications
You must be signed in to change notification settings - Fork 10
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
use throwing var methods for realm references to other objects #1035
Comments
@tomholub |
I'm thinking, when converting from RealmObject to a general model, throw if these cross-referenced objects are missing. Then general models would not have optional objects, if we meant the objects to be required. For example, a private key is meaningless if it doesn't belong to a particular user. So a key with a nil |
We have
and in |
Yes, but look at this: extension KeyInfoRealmObject {
/// associated user email
var account: String? {
user?.email
}
} user should never be nil, therefore there should be guard and throw, and it should return a Same problem here: extension ClientConfigurationRealmObject: CachedRealmObject {
var identifier: String { userEmail ?? "" }
var activeUser: UserRealmObject? { user }
} actually there are two problems above:
And so on |
@tomholub
How to deal with this case? |
This will overlap with user property in object. We have different semantic here: in object we could have optional user link because Realm requires it, but in cache protocol we should have user.
|
There is no reason for Then that will also solve this problem. |
Then we can call it |
Could you please explain what was the idea of For example if we want to remove
|
yes.. sorry about another ridiculous PR |
Initially idea was to have some service responsible for caching with injected storage, so Realm is not exposed all over the app. For convenience you are dealing with models, not realm models, so on client side of this service there is only object which conforms to CachedRealmObject (was different naming). So realm is not exposed to all over the app Initially, I wanted to make it more generic with Object and storage for the object. But now I'm not sure it's already needed. |
also from usage perspective you don't need to deal with realm interface to get, remove or save objects
|
just a note, this
the |
…jects (#1165) * Use throwing var methods for realm references to other objects * Code review fixes * Code review fixes * Code review fixes
This looks good. Probably for another issue/PR?
The advantage is that an exception can be captured and handled (in the general error handling somewhere in VC, wherever user action was initiated) while a forced unwrap cannot.
Originally posted by @tomholub in #1030 (comment)
The text was updated successfully, but these errors were encountered: