简体   繁体   English

编译器抱怨在删除函数数组中的索引时“表达式解析为未使用的函数”

[英]Compiler complains that 'Expression resolved to unused function' when removing index in array of functions

I created this test case with 2 types and as expected the 'Int' case works. 我用2种类型创建了这个测试用例,并且正如预期的那样,“ Int”用例起作用。 The Callback one doesn't. 回调没有。 Not sure why this is happening. 不知道为什么会这样。 I've been trying lots of things. 我一直在尝试很多事情。 I may be missing something obvious? 我可能缺少明显的东西?

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 is trying to tell you that you have an expression that is returning a function type, but you never call it Resolving to an unused function是试图告诉您您有一个返回函数类型的表达式,但是您从不调用它

So,you just need try to use it 所以,您只需要尝试使用它

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM