0

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

code kid
  • 374
  • 1
  • 6
  • 22

1 Answers1

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

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

typealias IntegerTransform = (Int) -> Int
var variableThatWillBeAssignedAFunction: IntegerTransform?
Greg de J
  • 320
  • 1
  • 2
  • 8