swiftui-view-refactor
यह क्या करती है
यह स्किल SwiftUI व्यू कोड को दोबारा ढाँचा देती है ताकि उसे पढ़ना और संभालना आसान हो। यह उन iOS डेवलपर्स के लिए है जिनके व्यू बड़े या उलझे हुए हैं।
कब इस्तेमाल करें
- ✓जब किसी SwiftUI व्यू फ़ाइल का आकार बहुत बढ़ गया है और पढ़ना मुश्किल है।
- ✓जब किसी व्यू की बॉडी बहुत लंबी है और उसे छोटे हिस्सों में बाँटना चाहिए।
- ✓जब आप चाहते हैं कि किसी व्यू की स्टेट और डिपेंडेंसी एक तय तरीके से सेट हों।
Skill का लिंक
https://github.com/steipete/agent-scripts/blob/main/skills/swiftui-view-refactor/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“यह SwiftUI स्क्रीन की फ़ाइल बहुत बड़ी है। इसे साफ़ ढाँचे वाले छोटे व्यू में रिफ़ैक्टर कीजिए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट व्यू की प्रॉपर्टीज़ और कोड पर एक एकसमान क्रम लागू करता है, बड़ी बॉडी को सबव्यू में बाँटता है, और अतिरिक्त व्यू मॉडल के बजाय सरल स्टेट और environment इंजेक्शन को प्राथमिकता देता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
SwiftUI View Refactor
Attribution: copied from @Dimillian’s Dimillian/Skills (2025-12-31).
Overview
Apply a consistent structure and dependency pattern to SwiftUI views, with a focus on ordering, Model-View (MV) patterns, careful view model handling, and correct Observation usage.
Core Guidelines
1) View ordering (top → bottom)
- Environment
private/publiclet@State/ other stored properties- computed
var(non-view) initbody- computed view builders / other view helpers
- helper / async functions
2) Prefer MV (Model-View) patterns
- Default to MV: Views are lightweight state expressions; models/services own business logic.
- Favor
@State,@Environment,@Query, andtask/onChangefor orchestration. - Inject services and shared models via
@Environment; keep views small and composable. - Split large views into subviews rather than introducing a view model.
3) Split large bodies and view properties
- If
bodygrows beyond a screen or has multiple logical sections, split it into smaller subviews. - Extract large computed view properties (
var header: some View { ... }) into dedicatedViewtypes when they carry state or complex branching. - It's fine to keep related subviews as computed view properties in the same file; extract to a standalone
Viewstruct only when it structurally makes sense or when reuse is intended. - Prefer passing small inputs (data, bindings, callbacks) over reusing the entire parent view state.
Example (extracting a section):
var body: some View {
VStack(alignment: .leading, spacing: 16) {
HeaderSection(title: title, isPinned: isPinned)
DetailsSection(details: details)
ActionsSection(onSave: onSave, onCancel: onCancel)
}
}
Example (long body → shorter body + computed views in the same file):
var body: some View {
List {
header
filters
results
footer
}
}
private var header: some View {
VStack(alignment: .leading, spacing: 6) {
Text(title).font(.title2)
Text(subtitle).font(.subheadline)
}
}
private var filters: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(filterOptions, id: \.self) { option in
FilterChip(option: option, isSelected: option == selectedFilter)
.onTapGesture { selectedFilter = option }
}
}
}
}
Example (extracting a complex computed view):
private var header: some View {
HeaderSection(title: title, subtitle: subtitle, status: status)
}
private struct HeaderSection: View {
let title: String
let subtitle: String?
let status: Status
var body: some View {
VStack(alignment: .leading, spacing: 4) {
Text(title).font(.headline)
if let subtitle { Text(subtitle).font(.subheadline) }
StatusBadge(status: status)
}
}
}
4) View model handling (only if already present)
- Do not introduce a view model unless the request or existing code clearly calls for one.
- If a view model exists, make it non-optional when possible.
- Pass dependencies to the view via
init, then pass them into the view model in the view'sinit. - Avoid
bootstrapIfNeededpatterns.
Example (Observation-based):
@State private var viewModel: SomeViewModel
init(dependency: Dependency) {
_viewModel = State(initialValue: SomeViewModel(dependency: dependency))
}
5) Observation usage
- For
@Observablereference types, store them as@Statein the root view. - Pass observables down explicitly as needed; avoid optional state unless required.
Workflow
- Reorder the view to match the ordering rules.
- Favor MV: move lightweight orchestration into the view using
@State,@Environment,@Query,task, andonChange. - If a view model exists, replace optional view models with a non-optional
@Stateview model initialized ininitby passing dependencies from the view. - Confirm Observation usage:
@Statefor root@Observableview models, no redundant wrappers. - Keep behavior intact: do not change layout or business logic unless requested.
Notes
- Prefer small, explicit helpers over large conditional blocks.
- Keep computed view builders below
bodyand non-view computed vars aboveinit. - For MV-first guidance and rationale, see
references/mv-patterns.md.
अक्सर पूछे जाने वाले सवाल
क्या यह हर स्क्रीन में व्यू मॉडल जोड़ती है?
नहीं। स्किल हल्के पैटर्न को प्राथमिकता देती है, जिसमें व्यू सरल रहते हैं और बिज़नेस लॉजिक मॉडल के पास रहता है।
व्यू फ़ाइल में प्रॉपर्टीज़ कहाँ रखी जाएँ?
एक तय क्रम में, जो environment वैल्यू से शुरू होता है और फिर स्टोर की गई प्रॉपर्टीज़ आती हैं।
कोई हेल्पर कब अपना अलग व्यू बने?
जब उसके पास अपनी स्टेट या जटिल ब्रांचिंग हो, या दोबारा इस्तेमाल उसे ढाँचे के हिसाब से सही बनाए।
जानकारी
लेखक का मूल विवरण
SwiftUI view refactor/review: layout, DI, Observation, view models.
repo: steipete/agent-scripts
लोकप्रियता
- GitHub स्टार
- 7.4k
- रैंकिंग में स्थान
- #13251
- लाइसेंस
- MIT
- अपडेट की गई
- 30/10/2026
कमेंट
- …
इस repository की और skills
beeper
7.4kआपके एजेंट को आपकी लोकल Beeper चैट हिस्ट्री में संदेश खोजने और यह पता करने में मदद करती है कि कोई अस्पष्ट संकेत किस चैट या संपर्क का है।
cloudflare-registrar
7.4kआपके एजेंट को Cloudflare Registrar पर डोमेन की कीमत और उपलब्धता जाँचने, और पुष्टि के बाद डोमेन रजिस्टर या सूचीबद्ध करने में मदद करती है।
codexbar
7.4kआपके एजेंट को Codex, Claude और Kimi जैसी AI सेवाओं पर आपका कितना उपयोग बचा है, यह जाँचने में मदद करती है, जिसमें सीमा, क्रेडिट और रीसेट का समय शामिल है।
create-cli
7.4kआपके एजेंट को कमांड लाइन टूल के कमांड, फ़्लैग, हेल्प टेक्स्ट, आउटपुट और एरर इस तरह डिज़ाइन करने में मदद करती है कि वह लोगों और स्क्रिप्ट दोनों के लिए काम करे।
मिलती-जुलती skills
android-clean-architecture
280kयह आपके एजेंट को Android projects को व्यवस्थित तरीके से संभालने देता है। यह code को ऐसा ढांचा देता है कि उसकी देखभाल और नए features जोड़ना आसान हो।
compose-multiplatform-patterns
280kKMP projects में Compose Multiplatform और Jetpack Compose patterns इस्तेमाल करने में आपके एजेंट की मदद करता है। इसमें state, navigation, theming और performance शामिल हैं।
dart-flutter-patterns
280kयह आपके एजेंट को Dart और Flutter apps के लिए code लिखने देता है। यह आधुनिक patterns इस्तेमाल करके मज़बूत और आसानी से संभलने वाले apps बनाता है।