0

When working with Swift - Extensions

As you know, we can create variables for function. i want to create a variable which can hold reference to a function which has parameters.

i have managed to create variable for a function which didn't have any parameters defined for

My code is as follows :-

extension UIAlertController {


    var cancelBlock : ()->Void  { return {} }

    var nameBlock : (nameArg:String?)->Void  { }

}

I am getting the following error with "nameBlock"

Computed property must have accessors specified

How should i specify return value ?

Pawan Joshi
  • 1,581
  • 3
  • 20
  • 40

1 Answers1

0

use
var nameBlock : (nameArg:String?)->Void? { return nil }

rahulchona
  • 592
  • 4
  • 10
  • this is a computed property that should return an optional method but instead of it it always returns nil. I am still trying to understand what would be the use of it – Leo Dabus Apr 11 '16 at 06:55