Bird
0
0

Which of the following is the correct syntax to create a horizontal stack with two Text views in SwiftUI?

easy📝 Syntax Q12 of 15
iOS Swift - SwiftUI Basics
Which of the following is the correct syntax to create a horizontal stack with two Text views in SwiftUI?
?
AHStack -> Text("Hello") + Text("World")
BHStack(Text("Hello"), Text("World"))
CHStack[Text("Hello"), Text("World")]
DHStack { Text("Hello") Text("World") }
Step-by-Step Solution
Solution:
  1. Step 1: Recall SwiftUI stack syntax

    Stacks use braces { } to group child views, separated by spaces or newlines.
  2. Step 2: Identify correct syntax

    HStack { Text("Hello") Text("World") } uses braces and places Text views inside correctly. Others use invalid syntax.
  3. Final Answer:

    HStack { Text("Hello") Text("World") } -> Option D
  4. Quick Check:

    Use braces for stacks [OK]
Quick Trick: Stacks use braces { } to group views [OK]
Common Mistakes:
  • Using parentheses instead of braces
  • Using brackets instead of braces
  • Trying to use operators to combine views

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes