从数组中删除闭包但不使用它会导致编译器错误“表达式解析为未使用的函数”.除了将函数分配给一次性变量之外,还有一种避免这种情况的好方法吗?
原文链接:https://www.f2er.com/swift/319311.htmltypealias StringFunction = () -> String var list = [StringFunction]() list.append({ "Hello World!" }) let hi = list[0]() // "Hello World!" list.removeAtIndex(0) // Expression resolves to an unused function let _ = list.removeAtIndex(0) // Works