Wednesday, 15 May 2013

Swift: Error when trying to call a closure in an instance function -


I am trying to define a class that includes the closure to update its variables. Class definition:

  class layout {name: string ware choHash: [string: string] var jungHash: [string: string] var jongHash: [string: string] update drawer: ( String: string), [string: string], [string: string] - & gt; (String: string), [string: strings], [string: strings], janghash: [string: string], zongahash: [string: string], updater: ([string: string], [string: string], [string: String] -> ()) {self.name = name self.choHash = choHash self.jungHash = jungHash self.jongHash = JongHash self.updater = updater} func update () - & gt; () {Self.updater (self.choHash, self.jungHash, self.jongHash) // Here error}}  

So this is very similar to what I'm doing in Ruby, for example. However, XCode here shows an error:

'(@love [string: string], @lvalue [string: string], @lvalue [string: string] -> $ t8' is not the same ' (String: string), [string: string], [string: string] -> ()) '

I have two questions:

  1. Why is it, and how can I solve this problem? In particular, why does it consider the statement as going to @lalveue [string: string] instead of [string: string]?

  2. After the problem was solved, variables congress, Junghash and Jong hash were updated properly?

The problem is that type:

  ([string: string], [string: string], [string: string] - gt; ())  

is not function type.

This is a 3-tupal with two dictionaries and one dictionary with zero functions.

If you want a function that has 3 dictionaries, then you need to:

  ([string: string], [string: string] ], [String: string]) - & gt; ()  

If you type in the let and in the init argument, then it compile exactly.

She said, when you say:

What variable options, Chausash, Janghash and Jong hash will be updated properly?

The answer is - probably not. What are you expecting, when you call x.update for the dictionaries in the x call? If so, they will not be there (unless it is closed, a reference can be found back at x ) is passed from the dictionary value in Swift, so long as they are one No passwords are passed as inout parameters, no functions can change, the values ​​passed by the caller will change.


No comments:

Post a Comment