Singleton in swift is not accessible from another class -


i new swift , trying access 'problemsolved' array appended during gameplay in main gamecontroller class, class. reason array not visible in uiviewcontroller class want show problems solved in table. have read many of singleton examples on site see if it, doesn't seem to. or advice here appreciated!

class gamecontroller: tiledragdelegateprotocol, centerviewcontrollerdelegate {    static let sharedinstance = gamecontroller()    var problemssolved = array<string>()       func onproblemsolved() {      problemssolved.append(problem)      println("problemssolved contains \(problemssolved)") } } 

during gameplay can see in console array being appended ok in gamecontroller. when try access in viewcontroller class contents showing empty [].

class sidepanelviewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate {  @iboutlet weak var tableview: uitableview!  override func viewdidload() { tableview.reloaddata() println("the array viewed here empty \(gamecontroller.sharedinstance.problemssolved)")  } 

at moment can imagine don't call

gamecontroller.sharedinstance.onproblemsolved() 

when want append string problemssolved.

you should consider making functions , variables in gamecontroller static.

if doesn't solve problem need more information how , when add problemssolved.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -