Error404 Error404 - 1 year ago 92
iOS Question

How can I call a function of UIViewController from its reference on a different swift file?

I have got my current

on a swift file:

let currentController = self.navigationController?.visibleViewController

and I have a function on the swift file associated to the actual

What I am trying to do is to call that function from the first file but I am not able to do it. I tried doing:


but an error is shown:

Value of type 'UIViewController?' has no member 'chargeData'

I can guess from the error log that of course it is not recognizing the swift file in which the actual
is associated.

So what should I do to access to the function of my actual
from its reference?

Thanks in advance!

Answer Source

You have to typecast your currentController variable in order to call any method you created on your own.

let currentController = self.navigationController?.visibleViewController as? YourViewController //Here YourViewController is the name of the UIViewController subclass you created

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download