Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想创建一个可以分配函数(或可以为零)的可选变量。我猜它看起来像这样,但以下代码无法编译。
var variableThatWillBeAssignedAFunction: {(Int) -> Int}?
谢谢你的帮助
var variableThatWillBeAssignedAFunction: ((Int) -> Int)?
为了使其更具可读性,您还可以使用类型别名:
typealias IntegerTransform = (Int) -> Int var variableThatWillBeAssignedAFunction: IntegerTransform?