Printing whole object won’t work in most cases because you will receive the name of class and memory address of the object.
Even printing description property of the object won’t help, it will give you the same result.
Example:
let viewController = ViewController()
print(“ViewController description: \(viewController)”)
OUTPUT
ViewController description: <SimpleApp.ViewController: 0x103e03c20>
To solve it you can override description and put there whatever you want.
There are at least two ways how to do it. One is inside the class and the other is using the extension. In this case, we will use that second option. We have one property viewControllerName which we want to display in the console.
let viewControllerName = “SmashSwiftViewController”
extension ViewController {
override var description: String {
return self.viewControllerName + “, some more important information to show in description.”
}
}
Execute previous code again.
let viewController = ViewController()
print(“ViewController description: \(viewController)”)
OUTPUT
ViewController description: SmashSwiftViewController, some more important information to show in description.