简体   繁体   中英

How do you create an optional variable that is assigned a function in Swift

I would like to create an optional variable that can be assigned a function ( or can be nil). I'm guessing it would look something like this but the following code does not compile.

var variableThatWillBeAssignedAFunction: {(Int) -> Int}?

Thanks for your help

var variableThatWillBeAssignedAFunction: ((Int) -> Int)?

To make it more readable, you can also use a typealias:

typealias IntegerTransform = (Int) -> Int
var variableThatWillBeAssignedAFunction: IntegerTransform?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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