Closures in Swift, SwiftUI

Hello everyone. WELCOME TO THE ANONYMOUS FUNCTION. Today the topic is closures, which are a bit like anonymous functions. I would like to share with you the information I have learned on this subject and the experiences I have gained while learning about this subject. While sharing these, I hope that the article will be useful to you. I am going to try to explain all the information about the ANONYMOUS FUNCTION.

You can see the first example above.

A Swift closure may or may not return a value. If we want our closure to return some value, we need to mention its return type and use the return statement.

You can see the example above.

In addition, I want to mention is shorthand parameter. If one or more of a function’s final parameters are functions, you can use trailing closure syntax. You can also use shorthand parameter names such as $0 and $1, but I would recommend doing that only under the same conditions.

You can see the shorthand parameter above.

And also we can use closures as parameters when they accept parameters.

In conclusion, This article was the first article I wrote. I chose to share as a method when I learned what I learned. I hope I could be useful to you.

Resources I used to learn the information I shared above:

Thanks for reading this article. See you again with new topics.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store