Ziewvater Ziewvater - 5 months ago 43
Swift Question

Implementing debugDescription for DebugPrintable in Swift

I'm trying to write my own debug description for a Swift class. My code looks like the following:

class SceneData : DebugPrintable {
var fileName : String
var scene : Scene
var uuid : String

var debugDescription: String = {
return String(format: "<SceneData: {\n fileName: %s\n scene: %@\n}>", fileName, scene)
* More methods, etc.

I'm getting the error
'SceneData.Type' does not have a member named 'fileName'
, but
very clearly does have a variable
declared above. I'm also having similar issues when trying to use
within the string, and believe that this is related.

How can I make references to instance variables/
in the
string properly? I am pretty sure it is possible, both because other people have said it is, and because it seems ridiculous to have an object's debug description not have any actual specifics about itself. What am I doing wrong here?


remove =, because it should be a computed property.

var debugDescription: String{
        return String(format: "<SceneData: {\n  fileName: %s\n  scene: %@\n}>", fileName, scene)