Problem:
Added a Button in SwiftUI, but tapping it does nothing?
Solution:
You need an action closure!
Try: Button('Tap me') {
print('Tapped!')
}.
SwiftUI Buttons won’t fire without a task—add your logic inside the {}.
#SwiftUI#xcode
Problem:
SwiftUI Text view isn’t showing up in the preview?
Solution:
Wrap your Text in a VStack or HStack!
SwiftUI needs a layout container to render views.
Example:
VStack {
Text('Hello, SwiftUI!')
}
Hit Cmd+R to refresh the preview—there it is!
#xcode#swiftUI
code shortcut
============
Duplicate line (or multiple lines of code)
⌘ D ( command +D )
1- If nothing selected, the line which have cursor will be copied below.
2-If multiple line are selected, all will be copied
Xcode shortcut
============
Moving a full line (or many lines of code) up or down
1: ⌘ ⌥ { to move up
2: ⌘ ⌥ } to move down.
Imp:
If you have selected some text , Xcode will move each line containing your selection.
otherwise, it’ll move the line the cursor is in.