node ninja
node ninja

Reputation: 32986

how to access an object from another function

In viewDidLoad, an object is created. In some other function, I want to do something with the object, but outside of viewDidLoad, the object is not recognized. How can I access the object from other functions?

Upvotes: 0

Views: 93

Answers (2)

Greg Treleaven
Greg Treleaven

Reputation: 8454

If you want the object to be accessable by all other variables in the same level, you'll have to declare it in the same level as viewDidLoad and the other function.

//start of program
            //declare the object
            //declare viewDidLoad
              //--
            //declare other function
              //--
//end of program

Upvotes: 0

nacho4d
nacho4d

Reputation: 45098

you have to declare that object in your view controllers header (not in viewDidLoad). you can initialize the object in viewDidLoad. Now it will be visible in every method (not function) within that class. ;)

Upvotes: 3

Related Questions