UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.