Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS SwiftUI how to bring up extra actions like "Embed in VStack" when interacting with code?

I am looking at this SwiftUI tutorial and it suggests I can see extra actions upon Command-Clicking the SwiftUI elements in code. In my Xcode, this jumps me to the class definition.

enter image description here

I see there's an option in XCode 11.0 t change the Option key to show SwiftUI inspector, however, this still does not let me modify SwiftUI code elements using actions like "Embed in VStack"

How can I get both inspector and extra SwiftUI actions when interacting with SwiftUI Code (not the preview)?

enter image description here

enter image description here

like image 964
Alex Stone Avatar asked Jan 01 '20 12:01

Alex Stone


People also ask

How do I embed in VStack?

In the Project navigator, click to select ContentView.Command-click the text view to show the structured editing popover, and then choose Embed in VStack. Also set the font of the Vstack to . largeTitle using the font modifier. The preview shows the two text views vertically stacked.

What is the difference between swift and SwiftUI?

Like Java, C++, PHP, and C#, Swift is an imperative programming language. SwiftUI, however, is proudly claimed as a declarative UI framework that lets developers create UI in a declarative way.

What is VStack Swift?

VStack. The VStack allows you to stack views vertically, from top to bottom. You can further customize the view by adding alignment or spacing to the VStack. VStack(alignment: . leading, spacing: 16) { Text("Hello, world!") .

What is a VStack in Xcode?

Individually, HStack , VStack , and ZStack are simple views. HStack positions views in a horizontal line, VStack positions them in a vertical line, and ZStack overlays views on top of one another.


2 Answers

Extra SwiftUI actions show when Canvas is opened (shortcut: Option-Command-Enter or ⌥+⌘+↵):

when canvas close canvas is closed

when canvas is open canvas is opened

like image 153
Hrabovskyi Oleksandr Avatar answered Oct 25 '22 16:10

Hrabovskyi Oleksandr


Instead of using the mouse, I recommend using the Xcode hotkey for bringing up code actions. Navigate to Preferences -> Key Bindings and search for Show Code Actions. You'll see the preset hotkey which you can then customize. My default key binding was Shift+Command+A. Just make sure you cursor is over the intended element when you press the hotkey.

enter image description here

like image 39
Nathan Dudley Avatar answered Oct 25 '22 15:10

Nathan Dudley