"instance member cannot be used on type" error on Swift 4 with nested classes -
i have class nested class. i'm trying access variables of outer class within nested class:
class thing{ var name : string? var t = thong() class thong{ func printme(){ print(name) // error: instance member 'name' cannot used on type 'thing' } } }
this however, gives me following error:
instance member 'name' cannot used on type 'thing'
is there elegant way circumvent this? hoping nested classes capture lexical scope, closures do.
thanks
you this
class thing{ var name : string = "hello world" var t = thong() init() { t.thing = self t.printme() } class thong{ weak var thing: thing! func printme(){ print(thing.name) } } }
Comments
Post a Comment