演示者功能永远不会在swift 3上读取 [英] presenter function is never read on swift 3

查看:86
本文介绍了演示者功能永远不会在swift 3上读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用我的演示者正在执行的协议中列出的演示者功能,但是每当我调用它时,它就永远不会出现在内部, 如何初始化演示者,以便可以调用界面函数?

I'm calling my presenter functon that is listed in a protocol that my presenter is implementing but whenever i call it it never goes inside, how do i initilize my presenter so i can call the interface funcion ?

这是我的视图控制器:

import UIKit

class FirstScreenViewController: UIViewController, MainViewProtocol {

    var myPresenter: MainPresenterProtocol?

    func outputPresenterFunction() {
       print (myPresenter?.presenterProtocolFuncTwo(numOne: 2, numTwo: 4, sucssesMessage: "Made it ?", failMessage: "failed :(" ) ?? "Default landed")
    }

}

我的演示者中有:

import Foundation

class MainPresenter: MainPresenterProtocol {

    var screenViewController: MainViewProtocol?

    func presenterProtocolFuncTwo(numOne: Int, numTwo: Int, sucssesMessage: String, failMessage: String) -> String {
        print("function is called")
        return "presenter function is called sussfuly"
    }

}

和我的协议本身:

protocol MainViewProtocol {
    func showSmallHeadline(textToShow: String)
    func showHeadline(textToShow: String)
}

protocol MainPresenterProtocol {
    static func presenterProtocolFuncOne()
    func presenterProtocolFuncTwo(numOne: Int, numTwo: Int, sucssesMessage: String, failMessage: String) -> String
    func presenterProtocolFucThree () -> Bool
}

每当我调用presenterProtocolFuncTwo时,我都会得到默认值,并且不会进入演示者的函数中

whenever i call the presenterProtocolFuncTwo, i get my default value and it doens't go inside the function in my presenter

推荐答案

您应该使用myPresenterscreenViewController属性来使用它们.

You should myPresenter and screenViewController properties to work with them.

protocol MainViewProtocol: class { ... }

class FirstScreenViewController: UIViewController, MainViewProtocol {
    var myPresenter: MainPresenterProtocol?

    override func viewDidLoad() {
        super.viewDidLoad()
        myPresenter = MainPresenter(controller: self)
    }
}

class MainPresenter: MainPresenterProtocol {
    weak var screenViewController: MainViewProtocol?

    init(controller: MainViewProtocol) {
        screenViewController = controller
    }
}

这篇关于演示者功能永远不会在swift 3上读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆