मुख्य सामग्री पर जाएँ
Skillpedia
मोबाइल ऐप7.4k · #13251

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 पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/steipete/agent-scripts/blob/main/skills/swiftui-view-refactor/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

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/public let
  • @State / other stored properties
  • computed var (non-view)
  • init
  • body
  • 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, and task/onChange for 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 body grows beyond a screen or has multiple logical sections, split it into smaller subviews.
  • Extract large computed view properties (var header: some View { ... }) into dedicated View types 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 View struct 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's init.
  • Avoid bootstrapIfNeeded patterns.

Example (Observation-based):

@State private var viewModel: SomeViewModel

init(dependency: Dependency) {
    _viewModel = State(initialValue: SomeViewModel(dependency: dependency))
}

5) Observation usage

  • For @Observable reference types, store them as @State in the root view.
  • Pass observables down explicitly as needed; avoid optional state unless required.

Workflow

  1. Reorder the view to match the ordering rules.
  2. Favor MV: move lightweight orchestration into the view using @State, @Environment, @Query, task, and onChange.
  3. If a view model exists, replace optional view models with a non-optional @State view model initialized in init by passing dependencies from the view.
  4. Confirm Observation usage: @State for root @Observable view models, no redundant wrappers.
  5. 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 body and non-view computed vars above init.
  • 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

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

beeper

7.4k

आपके एजेंट को आपकी लोकल Beeper चैट हिस्ट्री में संदेश खोजने और यह पता करने में मदद करती है कि कोई अस्पष्ट संकेत किस चैट या संपर्क का है।

डेटाडेटाबेस

cloudflare-registrar

7.4k

आपके एजेंट को Cloudflare Registrar पर डोमेन की कीमत और उपलब्धता जाँचने, और पुष्टि के बाद डोमेन रजिस्टर या सूचीबद्ध करने में मदद करती है।

कोडिंगडिप्लॉय और क्लाउड (DevOps)

codexbar

7.4k

आपके एजेंट को Codex, Claude और Kimi जैसी AI सेवाओं पर आपका कितना उपयोग बचा है, यह जाँचने में मदद करती है, जिसमें सीमा, क्रेडिट और रीसेट का समय शामिल है।

AI और एजेंटएजेंट

create-cli

7.4k

आपके एजेंट को कमांड लाइन टूल के कमांड, फ़्लैग, हेल्प टेक्स्ट, आउटपुट और एरर इस तरह डिज़ाइन करने में मदद करती है कि वह लोगों और स्क्रिप्ट दोनों के लिए काम करे।

कोडिंगसामान्य कोडिंग

मिलती-जुलती skills