Wade Sellers Wade Sellers - 2 years ago 165
Swift Question

Swift - can only print object's memory address

I'm using the Yelp API and pulling down a YLPBusiness. When I attempt to print() or dump() the YLPBusiness, I only receive the memory address in the console log.

If I print(YLPBusiness.name) however, I will receive the name. How can I fully print out all property values of the YLPBusiness object?

Screen shot of code and console log

Answer Source

You should override your class description property:

func description() -> String {
    return "Business name: \(self.name), address: \(self.address), etc."

where you print all properties of YLPBusiness as you desire.

You can fix your problem mentioned in comments by turning your method into property:

public override var description: String {
    return "Business name: \(self.name), address: \(self.address), etc."

It happened because Swift detects discrepancies between overloading and overriding in the Swift type system and the effective behavior seen via the Objective-C runtime.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download