From the course: Complete Guide to SwiftUI
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Extract subviews
From the course: Complete Guide to SwiftUI
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. Now you can see here we get an error because we already have a…
Contents
-
-
-
-
(Locked)
Embed a stack view6m 29s
-
(Locked)
Text views3m 41s
-
(Locked)
Image views with SF Symbols5m 22s
-
(Locked)
Iteration with ForEach5m 13s
-
(Locked)
Images and assets4m 56s
-
(Locked)
Labels2m 22s
-
Add view2m 49s
-
(Locked)
Challenge: Add views26s
-
(Locked)
Solution: Add views2m 33s
-
(Locked)
Extract subviews8m 4s
-
(Locked)
Subviews with parameters6m 37s
-
(Locked)
Challenge: Ratings view44s
-
(Locked)
Solution: Ratings view3m 55s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-
-