agentleFS
kelvinkosbabkelvinkosbab/KozBon/.claude/skills/coredata-swift6-pro/SKILL.md

coredata-swift6-pro

Skill5 starsChanged 11 days agoMITView on GitHub

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.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 1 is distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Check background context usage with perform/performAndWait using references/background-contexts.md.

    line 15
  2. Very specific:

    Verify SPM compatibility for .xcdatamodeld bundling using references/spm-limitations.md.

    line 16
  3. Very specific:

    Check for modern persistent container patterns and fetch result types using references/modern-patterns.md.

    line 17
  4. Distinctive:

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

    line 20
  5. Very specific:

    All background context work goes through context.perform { } (async) or context.performAndWait { } (sync).

    line 28
  6. Very specific:

    Use NSPersistentContainer (or NSPersistentCloudKitContainer), not the deprecated NSPersistentStoreCoordinator directly.

    line 30
  7. Very specific:

    Prefer .viewContext.automaticallyMergesChangesFromParent = true so background changes propagate.

    line 31
  8. Very specific:

    SPM compatibility (high): Test container relies on Bundle.module for .momd — must build model programmatically.

    line 99

≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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.
  2. Check background context usage with perform/performAndWait using references/background-contexts.md.
  3. Verify SPM compatibility for .xcdatamodeld bundling using references/spm-limitations.md.
  4. Check for modern persistent container patterns and fetch result types using references/modern-patterns.md.
  5. 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.

// 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.

// 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.

// 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.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.