support for array of Views
murad1981 opened this issue · comments
the WrappingHStack
fires an error when I add array of Views inside like this:
enum SomeEnum: String, CaseIterable {
case tag1
case tag2
case tag3
case tag4
}
WrappingHStack { // <---- Initializer 'init(alignment:spacing:lineSpacing:content:)' requires that '[Text]' conform to 'View'
SomeEnum.allCases.map { tag in
Text(tag.rawValue)
}
}
I tried to wrap those views in a Group
but it didn't work either
When usign WrappingHStack, instead of ForEach
or similar you use WrappingHStack
. The reason behind this, is that it gives the possibility to differentiate between ForEach as one element (all items should be in one line) and WrappingHStack
's behaviour, which puts them in different lines.
Your code should look like this:
WrappingHStack(SomeEnum.allCases) {
Text($0.rawValue)
}
or if you want more items around:
WrappingHStack {
// some other content
WrappingHStack(SomeEnum.allCases) {
Text($0.rawValue)
}
// some other content
}