Extract Subview not showing up
Asked Answered
R

7

21

I'm building my first SwiftUI app. For some reason when I command+click on an HStack the "Extract Subview" and other options don't show up. Any reason why I'm not seeing these options? I'm using Core Data and UITableView.appearance to remove lines in my List as well. Does it have to do with using core data and my use of UITableView? Couldn't find any answers after researching. Appreciate the help.

enter image description here

Reverberation answered 2/5, 2020 at 19:38 Comment(0)
E
47

Not sure if this is an Xcode issue/bug but as of Xcode 11.4 the "Extract Subview" option (and others) show up only if the Canvas is being shown.
So, enable live preview and then cmd-click on the View you want to extract.

image

Education answered 2/5, 2020 at 20:20 Comment(4)
This works now. Even if you can't use live preview due to Core Data I still need to show the live preview screen to make the options visible. Thanks and appreciate the help!Reverberation
@KevinLillybridge Well... you can have Core Data and live preview at the same time as long as you set the .environment(\.managedObjectContext, context) in the PreviewProvider.Education
@KevinLillybridge Check this Core Data and SwiftUI. Look under the Composing our UI section and your live preview should work alongside Core Data ;)Education
I had to show the Canvas and restart Xcode to get it working again.Peewit
B
2

I was having the same problem but could not solve it with the presented solution. Came to realize that you need to have an Object embedded in another to be able to extract it. In the example below, I would not be able to extract the HStack, but it will show up in the VStack.

  struct ContentView: View {
    var body: some View {
            HStack(){
                Image("sal")
                    .resizable()
                    .frame(width: 100, height: 100)
                    .aspectRatio(contentMode: .fit)
                    .cornerRadius(20)
                    .padding(.trailing)
                VStack(alignment: .trailing){
                    Text("Camino La Angostura")
                    Text("2.5 Km.")
                }
            }
    }
}
Belligerent answered 29/11, 2022 at 9:51 Comment(0)
L
2

Try Control + Right Click.

Your welcome!

Lord answered 27/9, 2023 at 15:40 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Mariannmarianna
A
1

I got the same problem. You should do command + right click.

Azarria answered 26/7, 2022 at 3:35 Comment(0)
G
0

Command + double right click worked for me. Xcode 15.0.1

Gannon answered 12/5 at 21:1 Comment(0)
F
0

I had same issue and I found the Extract subview option.

Follow the following steps:

  1. Double click on curly braces
  2. Right click on selected item
  3. Now you can see the all options

Please check these screenshot:

Extract subview option

Franco answered 3/8 at 20:20 Comment(0)
G
-1

I was encountering the same problem and then I find a suggestion here that seems to solve it, basically you need an object embedded in another for it to work, for instance an hstack inside a vstack.

Gatling answered 24/3 at 19:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.