# Coredata Swift6 Pro

> Reviews Core Data code for Swift 6 strict concurrency compliance, modern context usage, and SPM compatibility. Use when reading, writing, or reviewing Core Data code under Swift 6.

- **Type:** Skill
- **Install:** `agentstack add skill-kelvinkosbab-appbootstrapai-coredata-swift6-pro`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [kelvinkosbab](https://agentstack.voostack.com/s/kelvinkosbab)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [kelvinkosbab](https://github.com/kelvinkosbab)
- **Source:** https://github.com/kelvinkosbab/AppBootstrapAI/tree/main/.claude/skills/coredata-swift6-pro

## Install

```sh
agentstack add skill-kelvinkosbab-appbootstrapai-coredata-swift6-pro
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

Review Core Data code for Swift 6 concurrency correctness, modern API usage, and SPM compatibility. Report only genuine problems - do not nitpick or invent issues.

Review process:

1. Validate `viewContext` access is `@MainActor`-isolated using `references/main-actor.md`.
1. Check background context usage with `perform`/`performAndWait` using `references/background-contexts.md`.
1. Verify SPM compatibility for `.xcdatamodeld` bundling using `references/spm-limitations.md`.
1. Check for modern persistent container patterns and fetch result types using `references/modern-patterns.md`.
1. Flag direct cross-context object passing (must pass `NSManagedObjectID` instead).

If doing a partial review, load only the relevant reference files.

## Core Instructions

- Target Swift 6 with strict concurrency. Core Data + Swift 6 has specific rules that must be followed.
- `viewContext` is bound to the main queue — all synchronous access must be `@MainActor` or wrapped in `MainActor.run`.
- `NSManagedObject` subclasses are NOT `Sendable`. Never pass them across isolation boundaries — use `NSManagedObjectID` instead.
- All background context work goes through `context.perform { }` (async) or `context.performAndWait { }` (sync).
- For SPM packages, `.xcdatamodeld` cannot be compiled to `.momd` by `swift build` — only Xcode can. Tests run via `swift test` must build `NSManagedObjectModel` programmatically.
- Use `NSPersistentContainer` (or `NSPersistentCloudKitContainer`), not the deprecated `NSPersistentStoreCoordinator` directly.
- Prefer `.viewContext.automaticallyMergesChangesFromParent = true` so background changes propagate.
- For tests, use `NSInMemoryStoreType` so each test has an isolated store.

## Output Format

Organize findings by file. For each issue:

1. State the file and relevant line(s).
2. Name the rule being violated.
3. Show a brief before/after code fix.

Skip files with no issues. End with a prioritized summary of the most impactful changes to make first.

Example output:

### CoreStorage/Tests/EntityStoreTests.swift

**Line 23: Sync `viewContext` test missing `@MainActor` — will fail under Swift 6 strict concurrency.**

```swift
// Before
@Test func createUpdateDeleteObject() throws {
    let store = EntityStore(...)
    try store.create(...)
}

// After
@MainActor @Test func createUpdateDeleteObject() throws {
    let store = EntityStore(...)
    try store.create(...)
}
```

**Line 45: Background context work missing `perform { }` block.**

```swift
// Before
let bgContext = container.newBackgroundContext()
let object = MyObject(context: bgContext)
object.value = "foo"
try bgContext.save()

// After
let bgContext = container.newBackgroundContext()
try await bgContext.perform {
    let object = MyObject(context: bgContext)
    object.value = "foo"
    try bgContext.save()
}
```

### CoreStorage/Tests/Utilities/KeyValue.swift

**Line 14: Test relies on `Bundle.module` for `.momd` — will fail under `swift test`.**

```swift
// Before
self.init(storeName: "MyModel", in: .module)

// After
let model = makeKeyValueManagedObjectModel()
self.init(storeName: "MyModel", managedObjectModel: model)
```

### Summary

1. **Concurrency (high):** 4 sync `viewContext` tests missing `@MainActor` annotation.
2. **SPM compatibility (high):** Test container relies on `Bundle.module` for `.momd` — must build model programmatically.
3. **Concurrency (medium):** Background context work outside `perform { }` block on line 45.

End of example.

## References

- `references/main-actor.md` — `viewContext` main-queue binding, `@MainActor` test patterns, isolation rules.
- `references/background-contexts.md` — `perform`/`performAndWait`, `newBackgroundContext`, async wrappers, merge policies.
- `references/spm-limitations.md` — `.xcdatamodeld` compilation, `Bundle.module` issues, programmatic `NSManagedObjectModel`.
- `references/modern-patterns.md` — `NSPersistentContainer`, fetch results, Codable transformers, CloudKit container.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [kelvinkosbab](https://github.com/kelvinkosbab)
- **Source:** [kelvinkosbab/AppBootstrapAI](https://github.com/kelvinkosbab/AppBootstrapAI)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-kelvinkosbab-appbootstrapai-coredata-swift6-pro
- Seller: https://agentstack.voostack.com/s/kelvinkosbab
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
