TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: SwiftUI Day 30, Project 5.2 - No implicit HStack for List

Forums > 100 Days of SwiftUI

Recently updated to Xcode 13, am going through SwiftUI a second time - newbie and was bamboozeled by some aspects first time around so hoping it will stick better next time around.

Have got to Day 30, and at the end of the first tutorial it says:

If we use a second view inside a List row, SwiftUI will automatically create an implicit horizontal stack for us so that everything in the row sits neatly side by side.

I remember the first time around this worked perfectly, however now that I am doing it with Xcode 13, it aligns them more like a VStack. I'd add an image however I am unsure how to do that here.

I opened up the first rendition, and it was showing it as VStack view as well. I launched the simulator, and still the same. I tried to add an HStack, which Xcode did not like at all:

cannot convert value 'usedWords' of type '[String]' to expected type 'Binding<[String]>', use wrapper instead

Has something changed? I looked for documentation of this but could not find anything either.

3      

Have managed to find a solution:

List(usedWords, id: \.self) { word in
     HStack {
          Image(systemName: "\(word.count).circle")
          Text(word)
     }
}

instead of:

List(usedWords, id: \.self) {
    Image(systemName: "\($0.count).circle")
    Text($0)
}

If anyone can explain why, would be grateful!

4      

Thank you for this.

I also noticed that implicit Hstack was not working and was trying to figure out how to get it to work.

I did the same approach as you but met with an error. Good job on figuring out we just need a variable name to identify each item in the array for our list!

3      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.