NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

Access a UIImageView outlet from another class

Forums > Swift

Hello i'm making an app with gesture recognizer and i've put the UIImageView outlets in the main ViewController but i have to acces them from another class.

I have that in the View Controller: @IBOutlet weak var myImageView: UIImageView!

how could i call myImageView from another class?

   

You can access the variable normally, just like you'd access any other variable (myVC.myImageView). The only thing is, you need to make sure viewDidLoad() has been executed beforehand, otherwise, the value will be nil.

   

Hacking with Swift is sponsored by Paw

SPONSORED Use Paw to build, test and describe web APIs. Paw has a lightning fast native macOS interface to compose requests, collaborate in real-time on API specs, and generate client code for your applications. You can import and export API definitions.

Discover Paw for Mac

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

Not logged in

Log in
 

Link copied to your pasteboard.