ProfileManagerDelegete

ProfileManagerDelegete

我有一个协议(protocol):

protocol ProfileManagerDelegete {
func dataHaveUpdated(type: ReturnType)

}

并创建一个协议(protocol)数组,并添加/删除监听器:
var listeners: [ProfileManagerDelegete] = []

func addListener(listener: ProfileManagerDelegete) {
    listeners.append(listener)
}

func removeLister(listener: ProfileManagerDelegete) {
    for lis in listeners {
        if lis == listener { // this line error
            //remove listener
        }
    }
}

有人可以帮忙吗?

最佳答案

因为您没有告诉Swift如何比较ProfileManagerDelegete类型的2个对象。定义一个函数:

protocol ProfileManagerDelegete {
    func dataHaveUpdated(type: ReturnType)
}

func == (lhs: ProfileManagerDelegete, rhs: ProfileManagerDelegete) -> Bool {
    // decide if they are equal
}

10-05 23:37