如何传递协议枚举数组在swift 4.0中运行?

Chi*_*dog 1 swift

我有一个类使用协议调用另一个类中的函数:

func calculateTableSize () {            
    // doing some stuff  
    // the call to the other function using the protocol
    summaryPresenter?.onCalculateTableSizeDone()     
}
Run Code Online (Sandbox Code Playgroud)

我想使用此函数传递一个类型为enum的数据数组:

class SummaryInteractor: SummaryScreenInteractorFunctionsProtocol {

    //sections
    enum Section: Int, CaseIterable {
        case header = 0, description, diagnoses, perscription, notes, addFaxHeadline,  addFax, addEmailHeadline, addEmails, givePermissionHeadline, selecAnswer, addNewEmail,addNewFax, removableText, headlineEmpty
    }

    var sectionData: [Section] = [
        .header
    ]

...
...
Run Code Online (Sandbox Code Playgroud)

问题显然是我不能在我的协议中添加这一行(这是我想要实现的):

//what will be written in the presenterFromTheInteractor
protocol SummaryScreenInteractorProtocol {
    func onCalculateTableSizeDone(data: [Section])
}
Run Code Online (Sandbox Code Playgroud)

因为那时协议(以及所有其他类都不会知道这个新的Enum类型,什么是Selection.

因此,它出错了:

func calculateTableSize () {            
    // doing some stuff  
    // the call to the other function using the protocol
    summaryPresenter?.onCalculateTableSizeDone()     
}
Run Code Online (Sandbox Code Playgroud)

我如何设法将该sectionData传递给我的其余功能?

谢谢

Rob*_*ler 6

您的枚举无法从协议访问,因为它嵌入在另一个类中.你有两个选择

  1. 将枚举移到外面

    enum Section {}
    
    class SummaryInteractor {}
    
    Run Code Online (Sandbox Code Playgroud)
  2. 指定枚举的位置: SummaryInteractor.Section

    func onCalculateTableSizeDone(data: [SummaryInteractor.Section])
    
    Run Code Online (Sandbox Code Playgroud)