In swift 2.0 is there a way to pass the type of the class in a variable so that I can later use it for checking if a object type 'is' that class type. Better explained thru following example :
class Base {..}
class Derived : Base {..}
var obj: Base = Derived()
if obj is Derived {
print("obj is Derived type")
}
This is fine. But I want to be ability to store the class type 'Derived' in a variable something like this :
let classType = Derived // Of course this will give compile error
And use it later to check the type of an object :
if obj is classType {..}
The closest I came to dealing with saving the Class type is:
let classType = Derived.self
This says the classType is of type 'Derived.Type', but you can't really use that for checking the object type as below :
if obj is classType {..blah.. } // Compile error.'Use of undeclared type 'classType'
I hope you are getting my point. I'm trying to store the class type in a variable and later use that to check if the object belongs to that type. Is there a way to do it. I looked at similar forums on stack overflow but nothing which came close to answering this.