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
Post a Comment