如何在Swift中传递协议枚举数组以发挥作用?
我有一个类使用协议调用另一个类中的函数:如何在Swift中传递协议枚举数组以发挥作用?,swift,Swift,我有一个类使用协议调用另一个类中的函数: func calculateTableSize () { // doing some stuff // the call to the other function using the protocol summaryPresenter?.onCalculateTableSizeDone() } 我想使用以下函数传递enum类型的数据数组: class SummaryInteractor:
func calculateTableSize () {
// doing some stuff
// the call to the other function using the protocol
summaryPresenter?.onCalculateTableSizeDone()
}
我想使用以下函数传递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
]
...
...
问题很明显,我无法在协议中添加以下内容,这正是我想要实现的:
//what will be written in the presenterFromTheInteractor
protocol SummaryScreenInteractorProtocol {
func onCalculateTableSizeDone(data: [Section])
}
因为协议和所有其他类都不知道这个新的枚举类型,什么是选择
所以它当然显示了错误:
使用未声明的类型“Section”
如何将该部分数据传递给我的其他函数
谢谢您的枚举无法从协议访问,因为它嵌入到另一个类中。你有两个选择 将枚举移到外部
enum Section {}
class SummaryInteractor {}
指定枚举的位置:SummaryInteractor.Section
您的枚举无法从协议访问,因为它嵌入到另一个类中。你有两个选择 将枚举移到外部
enum Section {}
class SummaryInteractor {}
指定枚举的位置:SummaryInteractor.Section
由于内部访问,无法访问枚举。最好将枚举放在类之外。由于内部访问,无法访问枚举。最好把枚举放在类之外。你能给我一些代码示例,说明你打算把枚举移到什么地方吗?或者如何指定enum Summary.interactor.section的位置,关于如何将枚举放在外面更好谢谢你,罗伯特,你认为做什么更好?@ChiefMadog我们应该问一个比我聪明的人,但在你的情况下,我认为没有区别,他们只是在不同的地方声明。我认为这取决于您的代码组织。您能给我一些代码示例,说明您打算将枚举移到哪里吗?或者如何指定enum Summary.interactor.section的位置,关于如何将枚举放在外面更好谢谢你,罗伯特,你认为做什么更好?@ChiefMadog我们应该问一个比我聪明的人,但在你的情况下,我认为没有区别,他们只是在不同的地方声明。我认为这取决于您的代码组织。