In C++ and C#, it’s possible to pass functions as parameters without having to create a temporary variable. So this in not really as expected. The code I posted compiles and runs correctly in two different “online swift compiler in a webpage” sites I tried (if you tweak the last line).
Ah, got you. I misread, yers that should work. although I’m not sure about type inference, as that could lead for some subtle errors when forgetting () but actually intending to call the function (ie let f = sayHi vs let f = sayHi() Not sure if that’s desirable. But I’ll log this for investigation, And passing it as parameter definitely should work.
It would be great if I could do this with one line of code:
foo(doit: sayHi)
where “sayHi” is a member function. I used to do this in C++ and C# all the time. I believe it’s totally type safe too. This is mainly the point of my post.
Yes, I agree with you about “let f = sayHi”. I don’t really plan to do that. I just included that to help you debug the issue.