ios - Adding Swift Closures as values to Swift dictionary -


I would like to make a swift dictionary that has string type keys and its values ​​in the form of closures. The following is the code I have, but it gives me an error:

'@lawlue' is not the same (string, () -> zero) '

  class commander {Private var command dict: [string: () - & gt; Zero]! Init () {self.setUpCommandDict (); } Func setUpCommandDict () {self.commandDict ["OpenAssessment_1"] = {println ("I'm locked inside"); }}}  

I have tried to see other questions on stack overflow, but it does not give me any satisfactory answer. So I would appreciate some help here.

If you call your init before your setup function, Should work:

  class CommandResolver {private var commandDict: [string: () - & gt; Zero] init () {commandDict = [:] setUpCommandDict ()} func setUpCommandDict () {commandDict ["OpenAssessment_1"] = {println ("I'm locked inside")}}}  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -