NEW: Learn to build the incredible iOS 15 Weather app today! >>

WordScramble: how do i get the systemImage and Text showing in the same row?

Forums > SwiftUI

Hello all,

To whoever can help, I've been trying to figure out what's wrong with my code but not sure where i'm going wrong. when putting the image systemName and Text inside the list, they're meant to automatically be put into a HStack by swift so they show on the same line is what i've understood but they show on different rows/lines for me.

struct ContentView: View {

    @State private var usedWords = [String]()
    @State private var rootWord = ""
    @State private var newWord = ""

    @State private var score = 0

    @State private var errorTitle = ""
    @State private var errorMessage = ""
    @State private var showingError = false

    var body: some View {
        NavigationView{
            VStack{

                TextField("Enter word", text: $newWord, onCommit: addNewWord)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                    .autocapitalization(.none)
                    .padding()

                    List(usedWords, id: \.self){
                        Image(systemName: "\($0.count).circle")
                        Text($0)
                    }
                Text("You currently have a score of: \(score)")
            }
            .navigationBarTitle(rootWord)
            .toolbar {
                ToolbarItem(placement: .navigationBarLeading){
                    Button("Start New Game", action: startGame)
                }
            }
            .onAppear(perform: startGame)
            .alert(isPresented: $showingError){
                Alert(title: Text(errorTitle), message: Text(errorMessage), dismissButton: .default(Text("OK")))
            }
        }

    }

   

See this post.

HStack has changed for Xcode 13.

   

Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS, you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.