Get the App
SLTechnology News&Howtos  ›  Development  › 

What does $0 mean in SwiftUI

Shulou Source: shulou.com Published: 2022-06-03 09:48:16 09月22日 Update

This article mainly introduces the meaning of $0 in SwiftUI, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

$0 represents the first parameter passed to the Swift closure, which is the syntax sugar of the Swift language. Swift automatically provides shorthand parameter names for inline closures, which can be referenced by names such as $0memery "1Power2".

Code

Import UIKitlet name = [1name 23jue 8jue 6] let reverseName = name.sorted (by: {$0 > $1}) let reverseName2 = name.sorted (by: {$1 > $0}) print (name) print (reverseName) print (reverseName2)

Do not use $0 $1 instead

Let numbers = [1 numbers 2 5 print 4 3 6 8 7] sortNumbers = numbers.sorted (by: {(a, b)-> Bool in return a < b}) print ("numbers -" + "\ (sortNumbers)")

Use $0J. 1

Let numbers = [1 numbers 2 5 7] var sortNumbers = numbers.sorted (by: {$0 < $1}) print ("numbers -" + "\ (sortNumbers)")

Thank you for reading this article carefully. I hope the article "what is the meaning of $0 in SwiftUI" shared by the editor will be helpful to you? at the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles parameters closures meaning name code value interest at the same time more friends knowledge editing industry grammar language information information channels channels references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei Apple vpn Linux