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
This is a good question, it highlights a few things about why Swift is so good:
- Closure are great at making simple and readable code.
- 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.
- The data.sorted closure works becase the sorted syntax requires a certain closure and pre-defines its data types.
- Swift is typed.
This topic was automatically closed after 166 days. New replies are no longer allowed.