[英]Compiler complains that 'Expression resolved to unused function' when removing index in array of functions
我用2種類型創建了這個測試用例,並且正如預期的那樣,“ Int”用例起作用。 回調沒有。 不知道為什么會這樣。 我一直在嘗試很多事情。 我可能缺少明顯的東西?
typealias Type1 = Int
typealias Type2 = ([AnyObject?]) -> Void
class Test {
private var cb1: [Type1]
private var cb2: [Type2]
init() {
cb1 = [Type1](count: 2, repeatedValue: 0)
cb2 = [Type2](count: 2, repeatedValue: { _ in })
}
func removeAtIndex(index: Int) {
cb1.removeAtIndex(index)
cb2.removeAtIndex(index)
}
}
Resolving to an unused function
是試圖告訴您您有一個返回函數類型的表達式,但是您從不調用它
所以,您只需要嘗試使用它
typealias Type1 = Int
typealias Type2 = ([AnyObject?]) -> Void
class Test {
private var cb1: [Type1]
private var cb2: [Type2]
init() {
cb1 = [Type1](count: 2, repeatedValue: 0)
cb2 = [Type2](count: 2, repeatedValue: { _ in })
}
func removeAtIndex(index: Int) {
cb1.removeAtIndex(index)
let result = cb2.removeAtIndex(index)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.