你可以
RootVCDelegate
代理数组,然后在您想要对代理执行操作时
delegats.forEach { ..... }
在分配委托时,只需将委托附加到
delegates
例子:
// Delegate Protocol
protocol RootVCDelegate {
fetch(results: [Objects]) //returning Void does nothing so no need to write it
}
// RootVC
class RootVC {
delegates: [RootVCDelegate]
prepare(for segue: UIStoryboardSegue) {
let destination = (segue.destination as? UINavigationController).rootViewController ?? segue.destination // how I like to handle things if there's a possibility of a UINavigationController housing my UIViewController
switch destination {
case _ as MapVC: delegates.append(destination)
case _ as ListVC: delegates.append(destination)
default: return
}
}
}
这可能就是你想要的?