$npx -y skills add rshankras/claude-code-apple-skills --skill data-exportGenerates data export/import infrastructure for JSON, CSV, PDF formats with GDPR data portability, share sheet integration, and file import. Use when user wants data export functionality, CSV/JSON/PDF export, GDPR compliance data portability, import from files, or share sheet for
| 1 | # Data Export Generator |
| 2 | |
| 3 | Generate production data export and import infrastructure -- JSON export via Codable, CSV generation with proper escaping, PDF report rendering with UIGraphicsPDFRenderer, GDPR-compliant full data export, file import with UTType-based picker, and share sheet integration. No third-party dependencies. |
| 4 | |
| 5 | ## When This Skill Activates |
| 6 | |
| 7 | Use this skill when the user: |
| 8 | - Asks to "add data export" or "export user data" |
| 9 | - Wants "CSV export" or "JSON export" or "PDF export" |
| 10 | - Mentions "GDPR data portability" or "right to data portability" |
| 11 | - Asks about "exporting all user data" for compliance |
| 12 | - Wants to "import data" from files or competitor apps |
| 13 | - Mentions "share sheet" for exporting data |
| 14 | - Asks about "data backup" or "data download" |
| 15 | |
| 16 | ## Pre-Generation Checks |
| 17 | |
| 18 | ### 1. Project Context Detection |
| 19 | - [ ] Check deployment target (iOS 16+ / macOS 13+) |
| 20 | - [ ] Check Swift version (requires Swift 5.9+) |
| 21 | - [ ] Identify data model layer (SwiftData, Core Data, custom structs) |
| 22 | - [ ] Identify source file locations |
| 23 | |
| 24 | ### 2. Existing Export Detection |
| 25 | Search for existing export code: |
| 26 | ``` |
| 27 | Glob: **/*Export*.swift, **/*Import*.swift, **/*CSV*.swift, **/*PDF*.swift |
| 28 | Grep: "UIGraphicsPDFRenderer" or "CSVExport" or "UIActivityViewController" or "ShareLink" or "fileExporter" |
| 29 | ``` |
| 30 | |
| 31 | If existing export code found: |
| 32 | - Ask if user wants to replace or add additional formats |
| 33 | - Identify which formats are already supported |
| 34 | |
| 35 | ### 3. Data Model Detection |
| 36 | Search for data models that need exporting: |
| 37 | ``` |
| 38 | Grep: "@Model" or "NSManagedObject" or "struct.*Codable" or "class.*Codable" |
| 39 | ``` |
| 40 | |
| 41 | Identify the models to build export conformances for. |
| 42 | |
| 43 | ## Configuration Questions |
| 44 | |
| 45 | Ask user via AskUserQuestion: |
| 46 | |
| 47 | 1. **Export formats needed?** |
| 48 | - JSON (structured, machine-readable, best for GDPR) |
| 49 | - CSV (tabular data, spreadsheet-compatible) |
| 50 | - PDF (formatted reports with headers, tables, branding) |
| 51 | - Multiple (select which combination) |
| 52 | |
| 53 | 2. **What data needs exporting?** |
| 54 | - All user data -- GDPR compliance (every piece of stored user data) |
| 55 | - Specific data types (user selects which models to export) |
| 56 | - Reports/summaries (aggregated data, not raw records) |
| 57 | |
| 58 | 3. **Do you need import capability?** |
| 59 | - No -- export only |
| 60 | - Yes -- from files (JSON, CSV via file picker) |
| 61 | - Yes -- from competitor apps (custom format parsing) |
| 62 | |
| 63 | 4. **How should users trigger export?** |
| 64 | - Share sheet (system share UI with multiple destinations) |
| 65 | - Settings screen (dedicated export section) |
| 66 | - Export button (inline in content views) |
| 67 | - Automatic backup (periodic export to iCloud/local) |
| 68 | |
| 69 | ## Generation Process |
| 70 | |
| 71 | ### Step 1: Read Templates |
| 72 | Read `templates.md` for production Swift code. |
| 73 | |
| 74 | ### Step 2: Create Core Files |
| 75 | Generate these files: |
| 76 | 1. `DataExportManager.swift` -- Central export coordinator with format routing |
| 77 | 2. `DataExportable.swift` -- Protocol for models that support export |
| 78 | |
| 79 | ### Step 3: Create Format-Specific Files |
| 80 | Based on configuration: |
| 81 | 3. `CSVExporter.swift` -- If CSV format selected |
| 82 | 4. `PDFExporter.swift` -- If PDF format selected |
| 83 | |
| 84 | ### Step 4: Create Import Files |
| 85 | If import capability selected: |
| 86 | 5. `DataImporter.swift` -- File picker and format parser |
| 87 | |
| 88 | ### Step 5: Determine File Location |
| 89 | Check project structure: |
| 90 | - If `Sources/` exists -> `Sources/DataExport/` |
| 91 | - If `App/` exists -> `App/DataExport/` |
| 92 | - Otherwise -> `DataExport/` |
| 93 | |
| 94 | ## Output Format |
| 95 | |
| 96 | After generation, provide: |
| 97 | |
| 98 | ### Files Created |
| 99 | ``` |
| 100 | DataExport/ |
| 101 | ├── DataExportable.swift # Protocol for exportable models |
| 102 | ├── DataExportManager.swift # Central export coordinator |
| 103 | ├── CSVExporter.swift # CSV generation (optional) |
| 104 | ├── PDFExporter.swift # PDF rendering (optional) |
| 105 | └── DataImporter.swift # File import (optional) |
| 106 | ``` |
| 107 | |
| 108 | ### Integration with Data Models |
| 109 | |
| 110 | **Make a model exportable:** |
| 111 | ```swift |
| 112 | struct Expense: Codable, DataExportable { |
| 113 | let id: UUID |
| 114 | let title: String |
| 115 | let amount: Double |
| 116 | let date: Date |
| 117 | let category: String |
| 118 | |
| 119 | // DataExportable conformance |
| 120 | static var csvHeaders: [String] { |
| 121 | ["ID", "Title", "Amount", "Date", "Category"] |
| 122 | } |
| 123 | |
| 124 | var csvRow: [String] { |
| 125 | [id.uuidString, title, String(format: "%.2f", amount), |
| 126 | ISO8601DateFormatter().string(from: date), category] |
| 127 | } |
| 128 | |
| 129 | var pdfDescription: String { |
| 130 | "\(title) - $\(String(format: "%.2f", amount)) (\(category))" |
| 131 | } |
| 132 | } |
| 133 | ``` |
| 134 | |
| 135 | **Export from a view:** |
| 136 | ```swift |
| 137 | struct ExpenseListView: View { |
| 138 | let expenses: [Expense] |
| 139 | @State private var exportURL: URL? |
| 140 | @State private var showShareSheet = false |
| 141 | |
| 142 | var body |