How do you retrieve the type of an object in Swift?
swift
Solution
If you just need to check an object's type, you can use the type check operator, `is`, as in:
if myObject is UIView {
// do something
}
If you want to try to call a method on the object but you aren't sure of the class, downcast the object to the type you need, like this:
if let myView = myObject as? UIView {
myView.layer.backgroundColor = myColor
}
Problem
I cannot seem to find a function or method that returns the type of an object in Swift. How does one retrieve the type or class of an object in Swift? I tried using Obj-C classes which obviously did not work. In python you have things like `type` or `isinstance` In Javascript you have `constructor`