mcpbeat Sign in

Persistence Setup Skill for Claude

Generates SwiftData or CoreData persistence layer with optional iCloud sync. Use when user wants to add local storage, data persistence, or cloud sync.

11k tokens
context cost
the whole folder, loaded on every use
8
files
instructions only
0
copies elsewhere
how many repositories repackaged it
585
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/rshankras/claude-code-apple-skills --skill persistence-setup

The instruction itself

31 sections, as written by the author

Persistence Setup Generator

Generates a production-ready persistence layer using SwiftData (iOS 17+) or CoreData with optional iCloud (CloudKit) sync.

When This Skill Activates

  • User asks to "add persistence" or "set up data storage"
  • User mentions "SwiftData", "CoreData", or "local storage"
  • User wants to "sync data to iCloud" or "enable cloud sync"
  • User asks about "offline storage" or "data models"

Pre-Generation Checks (CRITICAL)

1. Project Context Detection

Before generating, ALWAYS check:

# Check deployment target
cat Package.swift | grep -i "platform"
# Or check project.pbxproj

# Find existing persistence implementations
rg -l "ModelContainer|NSPersistentContainer|@Model|@Entity" --type swift

# Check for existing SwiftData models
rg "@Model" --type swift | head -5

# Check for CoreData stack
rg "NSManagedObjectContext|NSPersistentStore" --type swift | head -5

# Check existing entitlements for iCloud
cat *.entitlements 2>/dev/null | grep -i "icloud"

2. Framework Selection

Use SwiftData if:

  • Deployment target is iOS 17+ / macOS 14+
  • User explicitly requests SwiftData
  • No existing CoreData implementation

Use CoreData if:

  • Deployment target < iOS 17
  • Existing CoreData stack present
  • User explicitly requests CoreData

3. Conflict Detection

If existing persistence found:

  • Ask: Extend existing, migrate to SwiftData, or create separate?

Configuration Questions

Ask user via AskUserQuestion:

  • Framework choice?
  • SwiftData (iOS 17+, recommended)
  • CoreData (older targets)
  • Enable iCloud sync?
  • Yes (requires CloudKit entitlement)
  • No (local only)
  • Generate example model?
  • Yes (with sample Item model)
  • No (just infrastructure)

Generation Process

Step 1: Create Core Files

Always generate:

Sources/Persistence/
├── PersistenceController.swift    # Container setup
├── Repository.swift               # Repository protocol
└── SwiftDataRepository.swift      # Concrete implementation

If example model requested:

Sources/Persistence/Models/
└── Item.swift                     # Sample @Model

If iCloud enabled:

Sources/Persistence/CloudSync/
├── CloudKitConfiguration.swift    # Container identifier
└── SyncStatus.swift               # Sync monitoring

Step 2: Read Templates

Read templates from this skill:

  • templates/PersistenceController.swift
  • templates/Repository.swift
  • templates/SwiftDataRepository.swift
  • templates/ExampleModel.swift
  • templates/CloudKitConfiguration.swift (if iCloud)
  • templates/SyncStatus.swift (if iCloud)

Step 3: Customize for Project

Adapt templates to match:

  • Project naming conventions
  • Existing model patterns
  • Bundle identifier for CloudKit container

Step 4: Integration

Basic Integration:

@main
struct MyApp: App {
    let container = PersistenceController.shared.container

    var body: some Scene {
        WindowGroup {
            ContentView()
                .modelContainer(container)
        }
    }
}

With iCloud sync:

@main
struct MyApp: App {
    let container = PersistenceController.shared.container

    var body: some Scene {
        WindowGroup {
            ContentView()
                .modelContainer(container)
                .environment(\.syncStatus, SyncStatus.shared)
        }
    }
}

iCloud Sync Setup

Required Capabilities (Xcode)

  • iCloud capability:
  • Check "CloudKit"
  • Add container: iCloud.com.yourcompany.yourapp
  • Background Modes (optional, for background sync):
  • Check "Remote notifications"

Required Entitlements

<key>com.apple.developer.icloud-container-identifiers</key>
<array>
    <string>iCloud.com.yourcompany.yourapp</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
    <string>CloudKit</string>
</array>

CloudKit Dashboard Setup

  • Go to CloudKit Dashboard
  • Select your container
  • Schema is auto-created from @Model classes
  • Deploy schema to production before release

Generated Code Patterns

Repository Protocol

protocol Repository<T>: Sendable {
    associatedtype T: PersistentModel

    func fetch(predicate: Predicate<T>?, sortBy: [SortDescriptor<T>]) async throws -> [T]
    func insert(_ item: T) async throws
    func delete(_ item: T) async throws
    func save() async throws
}

SwiftData Model

@Model
final class Item {
    var title: String
    var timestamp: Date
    var isCompleted: Bool

    init(title: String, timestamp: Date = .now, isCompleted: Bool = false) {
        self.title = title
        self.timestamp = timestamp
        self.isCompleted = isCompleted
    }
}

Container with CloudKit

let container = try ModelContainer(
    for: Item.self,
    configurations: ModelConfiguration(
        cloudKitDatabase: .private("iCloud.com.yourcompany.yourapp")
    )
)

Verification Checklist

After generation, verify:

  • [ ] App launches without crashes
  • [ ] Data persists between app launches
  • [ ] Models compile without errors
  • [ ] (If iCloud) CloudKit container exists in dashboard
  • [ ] (If iCloud) Data syncs between devices
  • [ ] Repository pattern allows easy testing

Common Customizations

Adding New Models

@Model
final class Project {
    var name: String
    @Relationship(deleteRule: .cascade) var items: [Item]

    init(name: String, items: [Item] = []) {
        self.name = name
        self.items = items
    }
}

// Update container
let container = try ModelContainer(for: Item.self, Project.self)

Custom Fetch Descriptors

let descriptor = FetchDescriptor<Item>(
    predicate: #Predicate { $0.isCompleted == false },
    sortBy: [SortDescriptor(\.timestamp, order: .reverse)]
)
let items = try modelContext.fetch(descriptor)

Migration (SwiftData)

// SwiftData handles lightweight migrations automatically
// For complex migrations, use VersionedSchema

enum ItemSchemaV1: VersionedSchema {
    static var versionIdentifier = Schema.Version(1, 0, 0)
    static var models: [any PersistentModel.Type] { [Item.self] }
}

Troubleshooting

iCloud Sync Not Working

  • Check entitlements match CloudKit container
  • Verify CloudKit Dashboard shows your container
  • Check device is signed into iCloud
  • Deploy schema to production if testing on release build

Data Not Persisting

  • Verify modelContainer modifier is on root view
  • Check save() is called after modifications
  • Look for errors in Console.app

CloudKit Quota Exceeded

  • Default quota is generous (free tier: 100MB asset storage)
  • Consider pruning old data
  • Use cloudKitDatabase: .automatic for shared containers
  • networking-layer - For remote API data alongside local cache
  • settings-screen - Often uses @AppStorage (simpler persistence)

References

Other skills for the same job

different authors, same section of the catalogue
Protocolsio Integration
by christophacham
×4

Integration with protocols.io API for managing scientific protocols. This skill should be used when working with protocols.io to search, create, update, or publish protocols; manage protocol steps and materials; handle discussions and comments; organize workspaces; upload and manage files; or integrate protocols.io functionality into workflows. Applicable for protocol discovery, collaborative protocol development, experiment tracking, lab protocol management, and scientific documentation.

16k tokens
Tailored Resume Generator
by frostant
×4

Analyzes job descriptions and generates tailored resumes that highlight relevant experience, skills, and achievements to maximize interview chances

3k tokens
Excalidraw Diagram Generator
by github
vendor ×3

Generate Excalidraw diagrams from natural language descriptions. Use when asked to "create a diagram", "make a flowchart", "visualize a process", "draw a system architecture", "create a mind map", or "generate an Excalidraw file". Supports flowcharts, relationship diagrams, mind maps, and system architecture diagrams. Outputs .excalidraw JSON files that can be opened directly in Excalidraw.

36k tokens scripts
Expo Dev Client
by openai
vendor ×3

Build and distribute Expo development clients locally or via TestFlight

961 tokens
Executing Plans
by ZhanlinCui
×3

Use when you have a written implementation plan to execute in a separate session with review checkpoints

542 tokens
Anndata
by christophacham
×3

Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

16k tokens
Benchling Integration
by christophacham
×3

Benchling R&D platform integration. Access registry (DNA, proteins), inventory, ELN entries, workflows via API, build Benchling Apps, query Data Warehouse, for lab data management automation.

14k tokens
Biopython
by christophacham
×3

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.

24k tokens

How to use it

Copy the folder

Take rshankras/persistence-setup from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.