ViewExtractor
Extract SwiftUI views from ViewBuilder content. NOTE: You can now use `Groups.init(subviews:transform:)`/`ForEach.init(subviews:content:)` for iOS 18+.
Install / Use
/learn @GeorgeElsham/ViewExtractorREADME
ViewExtractor
Extract SwiftUI views from ViewBuilder content.
Installation
Follow the instructions at Adding Package Dependencies to Your App to find out how to install the Swift package. Use the link of this GitHub repo as the URL (https://github.com/GeorgeElsham/ViewExtractor).
Example #1
Create a vertical stack of views, separated by dividers.
View code
struct DividedVStack<Content: View>: View {
@ViewBuilder let content: Content
var body: some View {
Extract(content) { views in
VStack {
let first = views.first?.id
ForEach(views) { view in
if view.id != first {
Divider()
}
view
}
}
}
}
}
Usage
DividedVStack {
Text("View 1")
Text("View 2")
Text("View 3")
}
Result
<img width="400" alt="Example #1 result" src="https://user-images.githubusercontent.com/40073010/202593448-02ad4069-0c9a-4bff-85cd-ddd9313b3c51.png">Example #2
Create a vertical stack of views, only keeping views at indexes with a multiple of 2.
View code
struct IntervalVStack<Content: View>: View {
@ViewBuilder let content: Content
var body: some View {
Extract(content) { views in
VStack {
ForEach(Array(zip(views.indices, views)), id: \.1.id) { index, view in
if index.isMultiple(of: 2) {
view
}
}
}
}
}
}
Usage
IntervalVStack {
ForEach(0 ..< 10) { index in
Text("Index: \(index)")
}
}
Result
<img width="400" alt="Example #2 result" src="https://user-images.githubusercontent.com/40073010/202593730-594d45f9-6abf-46a8-8dba-1f93ec89e55d.png">Example #3
Create a stack of views, returning multiple views as a result, allowing it to be wrapped by another view. When modifiers are applied, they apply to each view returned. Note the use of ExtractMulti rather than just Extract.
View code
struct Divided<Content: View>: View {
@ViewBuilder let content: Content
var body: some View {
ExtractMulti(content) { views in
let first = views.first?.id
ForEach(views) { view in
if view.id != first {
Divider()
}
view
}
}
}
}
Usage
HStack {
Divided {
Text("View 1")
Text("View 2")
Text("View 3")
}
.border(Color.red)
}
Result
<img width="400" alt="Example #3 result" src="https://user-images.githubusercontent.com/40073010/202593772-bf61b3bb-3d64-4d5f-8a57-1132ed2ba2d2.png">Related Skills
qqbot-channel
344.1kQQ 频道管理技能。查询频道列表、子频道、成员、发帖、公告、日程等操作。使用 qqbot_channel_api 工具代理 QQ 开放平台 HTTP 接口,自动处理 Token 鉴权。当用户需要查看频道、管理子频道、查询成员、发布帖子/公告/日程时使用。
docs-writer
99.8k`docs-writer` skill instructions As an expert technical writer and editor for the Gemini CLI project, you produce accurate, clear, and consistent documentation. When asked to write, edit, or revie
model-usage
344.1kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
Design
Campus Second-Hand Trading Platform \- General Design Document (v5.0 \- React Architecture \- Complete Final Version)1\. System Overall Design 1.1. Project Overview This project aims t
