0

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?

2 Answers 2

3

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. ;)

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.