我有一系列协议.现在我想通过查找数组的协议索引从数组中删除一个项目.但是,在将协议对象与数组中的项进行比较时,编译器会发出警告: ‘Protocol’ does not conform to AnyObject protocol S
‘Protocol’ does not conform to AnyObject
protocol SomeProtocol {} var list:[SomeProtocol] = [] func add(some:SomeProtocol) { list+=some } func remove(some:SomeProtocol) { var index = -1 for i in 0...list.count-1 { if [i] === some { index = i } } if index >= 0 { list.removeAtIndex(index) } }如果仅派生协议的类,则可以将协议定义更改为:
protocol SomeProtocol: class {}
然后,您将能够使用此协议的引用.