From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 23,200 courses taught by industry experts.

Closures in structs

Closures in structs

- [Instructor] Closures make up a lot of SwiftUI and other APIs in the Apple ecosystem. Understanding them makes for better code. Let's do some review of closures by looking at them in use with a struct for SwiftUI. Now I've made a small demo app to show a gradient of two colors on a rounded rectangle, on a ComputedGradientView. You can see it, right here, in the content field. And if we can go into ComputedGradientView, and it's a very simple thing right here, and it's just a rounded rectangle with a fill and that's all it really is. So it's very simple about what it's going to be doing, nothing that exciting and I just have this gradient, which is a constant. Now what if I wanted to have something a little more exciting than this? Now one way I could do this is I can go into my code, here, and type var gradient, and then make this a Gradient. And then I could, for example, take this code and you can see down here, I…

Contents