From the course: SwiftUI Essential Training

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Extract subviews

Extract subviews

- [Instructor] We have some places to add code to simplify our ContentView. Now we'll extract the code using two strategies. Our first strategy is going to require us to have a preview. So I'm going to hit Command + Option + Return and get the preview started here. Go up to ContentView. And you'll see here we have the ZStack. And the ZStack is a single view. So this is a one that's very easy to do for this kind of extraction. All you need to do here is click on the ZStack and do a Command + Click and you'll get that menu. You'll notice above the embeds we had before, you'll find one that says Extract Subview. So I can click on that and we get this thing that says ExtractedView. Now if you go down towards the bottom of your code, you'll see that we've got this thing called ExtractedView. And then I can click on that, and then right click to Refactor and then Rename it into a new name, which is HeaderView and hit Return.…

Contents