filmov
tv
Understanding Swift Trailing Closure Syntax
Показать описание
In this video I want to help you understand trailing closures and swift's trailing closure syntax and to help you make sense of some of the different initializers for controls like buttons and lists in SwiftUI.
You often hear people talk about making your code more Swifty. What exactly does that mean? I suppose it means different things to different people, but really, what it means is to write idiomatic Swift and by this, I mean to write code that looks and feels like Swift including swift specific language constructs and conventions and to avoid void patterns that might be more ore common in other programming languages.
A big part of this is the trailing closure syntax that is used.
As swift evolves, the language changes. As recent as Swift 5.3, the introduction to multiple trailing closures made for a simpler way to call a function with several closures and this made for simpler, more readable constructors for things like buttons.
If you want to support my work, you can buy me a coffee :)
Table of Contents:
0:00 Introduction
1:57 Introduction to Closures
6:57 Trailing Closures
12:41 Multiple Trailing Closures
18:50 Understanding the Button Initializer
23:47 Lists and onDelete closure
Starter Project Files:
(If you are having problems downloading zip files, use Safari. Chrome restricts zip files by default)
Completed Project:
References mentioned in video:
Closures Video:
Other References:
Stewart Lynch's YouTube Channel:
Stewart Lynch on Mastodon:
Stewart Lynch on Twitter:
Stewart Lynch on LinkedIn
You often hear people talk about making your code more Swifty. What exactly does that mean? I suppose it means different things to different people, but really, what it means is to write idiomatic Swift and by this, I mean to write code that looks and feels like Swift including swift specific language constructs and conventions and to avoid void patterns that might be more ore common in other programming languages.
A big part of this is the trailing closure syntax that is used.
As swift evolves, the language changes. As recent as Swift 5.3, the introduction to multiple trailing closures made for a simpler way to call a function with several closures and this made for simpler, more readable constructors for things like buttons.
If you want to support my work, you can buy me a coffee :)
Table of Contents:
0:00 Introduction
1:57 Introduction to Closures
6:57 Trailing Closures
12:41 Multiple Trailing Closures
18:50 Understanding the Button Initializer
23:47 Lists and onDelete closure
Starter Project Files:
(If you are having problems downloading zip files, use Safari. Chrome restricts zip files by default)
Completed Project:
References mentioned in video:
Closures Video:
Other References:
Stewart Lynch's YouTube Channel:
Stewart Lynch on Mastodon:
Stewart Lynch on Twitter:
Stewart Lynch on LinkedIn
Комментарии