How do I call a function in swift xcode

1

Good night, I have a function that is linked to a button, I would like to call it directly without the need of the button, what do I do?

The function ...

static func goToTutorialOrTo(market: Market, from viewController: UIViewController) {

    BusinessesContainer.selectedMarket = market

    AnswersHelper.sendAccessMarketTracker()

    if UserDefaultManager.didSawTutorial() {
        let rootMarketViewController = StoryBoard.rootMarketViewController()
        viewController.present(rootMarketViewController, animated: false, completion: nil)
    } else {
        let tutorialViewController = StoryBoard.main().instantiateViewController(withIdentifier: "tutorial")
        viewController.present(tutorialViewController, animated: true, completion: nil)
    }
}

The function called by the button ...

extension SupermercadosZonaViewController: UITableViewDelegate {
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        StoryBoard.goToTutorialOrTo(market: selectedMarketsToShowInTableView[indexPath.row], from: self)
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return StoryBoard.isIpad ? 175 : 110
    }
}

My attempt to call it directly

First ...

StoryBoard.goToTutorialOrTo(market: Market.init(json: <#T##JSON#>)!, from: self as! UIViewController)

Second ...

SupermercadosZonaViewController()

In neither case did I succeed.

    
asked by anonymous 16.05.2018 / 00:30

1 answer

1

The function you want to call is goToTutorialOrTo right? For the code you shared, this is a static function, ie it belongs to the class where it was defined.

To call it, you can do this:

Classe.goToTutorialOrTo(market: nil, from: nil)

Where Classe is the name of the class where this function is defined. Also do not forget to pass the parameters market and from .

    
16.05.2018 / 20:31