-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
indexOf
is throwing "Object type does not match RLMResults" exception
#2354
Comments
Just a guess, but is the object you're passing in not persisted? If that's indeed the issue, I'm preparing a patch right now both to (a) allow that and (b) give a more informative error when the classes actually don't match. |
Yes, actually, the object I'm passing in is not persisted, and I'm trying to match it against an object that may be persisted. Is that the issue? The "translator" simply takes a Model object and creates a new "Realm" object from it. Chances are, it's going to exactly match what is persisted, but the actual object itself isn't persisted. It's only created for comparison purposes. |
Great! Thanks! In the meantime, I can easily work around it by using |
I've written a persistence layer around RealmSwift. Everything works fine except I can't seem to use
indexOf
. When I do, it throws:Object type does not match RLMResults
. However, even when I look in the debugger, it shows I'm passing in the correct object type toindexOf
. Further details:In order to "wrap" Realm, I had to create a translation layer to translate between the Realm objects and the "Model" objects I use in the rest of the app.
Example:
I created a wrapper around
Results
, I calledDataset
. TheDataset
uses aTranslator
to translate between the objects returned byResults
and theModel
objects the rest of the app uses.Because of the limitations of Swift, I could not directly wrap
Results<T>
(Swift generic types are invariant). So instead, I extendedResults
with a protocol to provide the functions I needed.So
Dataset
wrapsRealmResults
and accessesResults<T>
using the protocol. This all works fine, except forindexOfObject
. It throwsObject type does not match RLMResults
even though I'm passing in the exact object thatResults
is expecting.You can see from the debugger that Results is:
Results<MessageObject>
and the type I'm passing in isMessageObject
. Any idea why this may be happening? Is it an issue or am I missing something?The text was updated successfully, but these errors were encountered: