Reputation: 5607
I want to do something like this:
class Dog: Object {
dynamic var name = ""
dynamic var age = 0
}
let results = realm.objects(Dog)
...but specify the object name as a variable.
This doesn't work:
let objectName = "Dog"
let results = realm.objects(objectName)
Neither does this:
let object = Dog
let results = realm.objects(object)
...or this:
let object = Dog()
let results = realm.objects(object)
...or this:
let object: Dog
let results = realm.objects(object)
Any ideas?
Upvotes: 0
Views: 585
Reputation: 11143
You can reference the type directly with Dog.self
:
let type = Dog.self
I don't have a project with realm, but in theory you should then be able to do something like:
let results = realm.objects(type)
Upvotes: 1