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
[RealmSwiftObject defaultPropertyValues]: unrecognized selector sent to class #4828
Comments
Hi @levibostian. Thanks for reaching out about this. I wanted to let you know that we've received your issue and that someone will follow-up with you soon. |
Thank you @istx25 |
The first thing that jumps out at me is that the If you refactor your code to avoid that, do you still hit this issue? If so, let me know ideally with a sample Xcode project, and I'll take a closer look. |
I do understand that I got the idea to creating an Is there another way to create an unmanaged instance from a managed instance of an object? I come from the realm-java lib where creating unmanaged instances of managed instances is built into the lib. What is the realm-cocoa equivalent or best practice instead? My use case: I perform a realm query to get a realm I am trying to create an unmanaged object because I can share the object across threads (as I will be on a different thread after the API call is performed since the API call will be performed on another thread and the callback after it is complete will be called from this API thread). I was looking through the Realm docs yesterday for Swift and it mentioned passing instances across threads. I am guessing this is the realm-cocoa equivalent to working with managed objects across threads? I don't mind this solution. However, it does not seem as flexible as creating an unmanaged object. Unmanaged objects are very flexible do handle them however you would like. The biggest limitation that I see is |
Hi @levibostian! Like JP said, the Realm To create an unmanaged version of let managedFooTask = realm.getFooTaskById(10)
let fooUnmanagedTask = PendingTask(value: managedFooTask) Creating unmanaged copies in order to pass them between threads would work, but it would be quite inefficient. You'd be paging in and making copies of each object you're working with, and you'd introduce the overhead of re-inserting the objects back into Realm as opposed to to simply updating the values you changed. If you have a need for tracking objects across multiple threads, and you want to minimize the number of times you need to create a thread reference, the technique we used to recommend before then was to assign a primary key property to each object, pass the primary key value itself across threads, and then use I hope that helped! |
@TimOliver, that is super helpful. Super helpful. I will give the I will look into If I decide to use So, I have been trying to do generic realm queries with no success. I understand generics. Been using them in Java for years. Swift is a little different, however (and not as complete as Java in terms of functionality) and have had issues getting it to work. Any tips on generic realm queries? Being able to query realm for a generic type (generic subclass of |
Hi @levibostian! Cool! Give it a try and let us know how you go! Hmm, generic queries? How would that look exactly? In terms of what I think you're hoping for, Realm doesn't do generic queries, sorry. When you perform a query in Realm, you specify the exact There's been some discussion about methods of applying polymorphic practices to Realm objects. I'd recommend checking that out if it's something you're curious about adopting. :) |
That's what I needed. Thank you. I have learned what I needed. Thank you so much for all the help, team. |
Awesome! Glad I was able to help! Thanks a lot! :) Best of luck! |
I am attempting to create an unmanaged instance of a managed Realm Object.
This is my Realm Object model for FooTask:
The crash happens on line:
If you notice in the Realm model that I have created,
FooTask
there are default values given for all of the properties. Would that be the issue with this crash?Goals
Create an unmanaged instance of a managed Realm Object.
Expected Results
Get an unmanaged instance of a managed Realm Object
Actual Results
Steps to Reproduce
Create an instance of
FooTask
somewhere in the app on a background thread. After the Realm write block is complete, send a notification via NSNotification. AppDelegate receives notification by observing it and then runs the code snippet given above in a new background thread where I am (1) querying Realm to get my managed instance ofFooTask
from the realm and (2) create an unmanaged instance of it.My managed realm object is valid as I set a breakpoint before:
let fooUnmanagedTask: Object = Object(value: managedFooTask as! Object)
andpo managedFooTask
to get a description of the object with class nameFooTask
and all properties populated with the correct values.I have read this issue which seems similar and what also told me to use
Object(value: )
to create an unmanaged instance of a managed object as well as this issue which gave me the hint to try and clean the project to see if that would fix this issue. I cleaned out all of my pods viarm -rf Pods/
and reinstalled them all viapod update
, then performed an Xcode Clean, ran the app again and same exception.Version of Realm and Tooling
The text was updated successfully, but these errors were encountered: