领域对象:
class Dog: Object {
dynamic var name = ""
dynamic var age = 0
}
致电结果:
let results = realm.objects(Dog)
或者这样做:
let type = Dog.self
let results = realm.objects(type)
我希望能够通过这样的方法来实现:
class SomeClass {
func callRealm(type: AnyObject) {
let results = realm.objects(type)
}
}
let someClass = SomeClass()
let type = Dog.self
someClass.callRealm(type)
我该怎么做?我对仿制药没有运气,尽管我认为这可能是要走的路。
答案 0 :(得分:2)
您的功能callRealm
应将输入设为AnyClass
而不是AnyObject
。
func callRealm(type: AnyClass) {
let results = realm.objects(type)
}