-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
I have created a struct that takes a function as an initializer argument. This is then run periodically (using a timer) in order to repeatedly perform some logic on a periodic basis. The timer portion works fine (thanks for that!), but Skip seems to have trouble with the function argument.
A contrived and simplified example, omitting the timer aspect:
struct DoThing {
var handler: (Int, Int) -> Int
func run() {
let result = self.handler(2, 5)
print("result = \(result)")
}
}
func addHandler(number1:Int, number2:Int) -> Int {
return number1 + number2
}
func multiplyHandler(number1:Int, number2:Int) -> Int {
return number1 * number2
}
let doThing1 = DoThing(handler: addHandler)
doThing1.run()
let doThing2 = DoThing(handler: multiplyHandler)
doThing2.run()
For this, Skip errors out with the following during compilation:
Function invocation 'addHandler(...)' expected
Function invocation 'addHandler(...)' expected
No value passed for parameter 'number1'
No value passed for parameter 'number1'
No value passed for parameter 'number2'
No value passed for parameter 'number2'
Type mismatch: inferred type is Int but (Int, Int) -> Int was expected
Type mismatch: inferred type is Int but (Int, Int) -> Int was expected
Function invocation 'multiplyHandler(...)' expected
Function invocation 'multiplyHandler(...)' expected
No value passed for parameter 'number1'
No value passed for parameter 'number1'
No value passed for parameter 'number2'
No value passed for parameter 'number2'
On iOS, this code results in the following (correct) output:
result = 7
result = 10
Metadata
Metadata
Assignees
Labels
No labels