0

Having a function getting a function as parameter:

mutating func updateAccessCaches(by areInIncreasingOrder: (NumberedFile, NumberedFile) -> Bool = sortByOldIDPrio) { ... }

How do I compare like

if areInIncreasingOrder == sortByOldIDPrio { ... }

I get the error

Binary operator '==' cannot be applied to operands of type '(DSRenamer.NumberedFile, DSRenamer.NumberedFile) -> Swift.Bool' and '(DSRenamer.NumberedFile, DSRenamer.NumberedFile) -> Swift.Bool'

Using other help from the internet, I was told that you can only compare if the function is the same, if you call both and if the result is the same, it is the same function? But that's obviously wrong.

So how can I decide if the reference of the functions are the same. Should be simple like in C, isn't it?

Peter71
  • 2,180
  • 4
  • 20
  • 33
  • 2
    The swift language deliberately does not support this: https://stackoverflow.com/questions/24111984/how-do-you-test-functions-and-closures-for-equality – Geoff Hackworth Apr 09 '23 at 07:27
  • "Should be simple like in C, isn't it?" in fairness, this was a bit of a mistake in C, too. It's a huge barrier to optimization, but since the language supported it at one point, it can never be removed without breaking decades of outstanding code. Check out the linked question for more details – Alexander Apr 09 '23 at 21:49

0 Answers0