About Closure with $0 and $1

Hello all. I wanna testing with $0 and $1, when i use it for closure. I search in case implemtentaion with arrayVariabel.sorted(by:{$0 < $1}). So how to implement it in that case? thank u
Screen Shot 2022-03-26 at 11.35.31

This is a good question, it highlights a few things about why Swift is so good:

  1. Closure are great at making simple and readable code.
  2. It’s great at inferring types given some amount of type of information, for example, in your first multiplyClosure above, it is able to infer that you are multiplying two Int values, since the return is Int. In the second multiplyClosure, Swift has no idea about the types, thus can’t apply an operator.
  3. The data.sorted closure works becase the sorted syntax requires a certain closure and pre-defines its data types.
  4. Swift is typed.

This topic was automatically closed after 166 days. New replies are no longer allowed.