"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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -