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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -