ios - Swift - how do I pass the type through a method call? -
a realm object:
class dog: object { dynamic var name = "" dynamic var age = 0 }
calling results:
let results = realm.objects(dog)
or doing way:
let type = dog.self let results = realm.objects(type)
i want able passing method this:
class someclass { func callrealm(type: anyobject) { let results = realm.objects(type) } } let someclass = someclass() let type = dog.self someclass.callrealm(type)
how this? i've had no luck generics, although think might way go.
your function callrealm
should take input anyclass
instead of anyobject
.
func callrealm(type: anyclass) { let results = realm.objects(type) }
Comments
Post a Comment