You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VariadicViews extends SwiftUI's capabilities by introducing a versatile way to extrapolate child views dynamically from opaque view content.
To know more about please read this awesome blog post from Moving Parts.
Usage
Integrating VariadicViews is as simple as integrating standard SwiftUI views.
import VariadicViews
UnaryVariadicView(content){ views inletlast= views.last?.id
ForEach(views){ view in
view
if view.id != last {Divider()}}}
UnaryVariadicChildren produces an unary container (like a VStack), MultiVariadicChildren produces a multi container (like a TupleView).
VariadicViewChildren is a collection of hashable and identifiable views.
Elements of VariadicViewChildren can handle view traits.
View traits work similar to preference values and can be read directly by subscripting VariadicViewChildren elements.
structMyString:ViewTraitKey{staticvardefaultValue:String?=.none
}extensionView{func myString(_ value:String)->someView{trait(key:MyTag.self, value: value)}}
// After using `myString` modifier in some of the views of content
MultiVariadicView(content){ children inVStack{ForEach(children){ child iniflet string =child[MyString.self]{Text(string)}}}}
Installation
Open Xcode, navigate to your project, and select File → Swift Packages → Add Package Dependency...
Enter the repository URL: https://github.com/lorenzofiamingo/swiftui-variadic-views and proceed by clicking Next.