Agent skill
coredata-cloudkit
CoreData and CloudKit patterns for data persistence and sync. Use when working on data models, migrations, sync logic, or query optimization.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/coredata-cloudkit
SKILL.md
CoreData + CloudKit Patterns
SwiftData Model Definition
@Model
final class TransactionEntity {
@Attribute(.unique) var id: UUID
var amount: Decimal
var note: String
var date: Date
var createdAt: Date
var updatedAt: Date
var deletedAt: Date? // Soft delete for CloudKit sync
@Relationship(deleteRule: .nullify)
var category: CategoryEntity?
@Relationship(deleteRule: .nullify)
var account: AccountEntity?
init(id: UUID = UUID(), amount: Decimal, note: String, date: Date) {
self.id = id
self.amount = amount
self.note = note
self.date = date
self.createdAt = Date()
self.updatedAt = Date()
}
}
Repository Pattern
protocol TransactionRepository: Sendable {
func getAll(filter: TransactionFilter?) async throws -> [Transaction]
func getById(_ id: UUID) async throws -> Transaction?
func save(_ transaction: Transaction) async throws
func delete(_ id: UUID) async throws
func batchImport(_ transactions: [Transaction]) async throws
}
CloudKit Sync Monitoring
final class SyncMonitor: ObservableObject {
@Published var syncStatus: SyncStatus = .idle
func startMonitoring() {
NotificationCenter.default.addObserver(
forName: NSPersistentCloudKitContainer.eventChangedNotification,
object: nil, queue: .main
) { notification in
guard let event = notification.userInfo?[
NSPersistentCloudKitContainer.eventNotificationUserInfoKey
] as? NSPersistentCloudKitContainer.Event else { return }
self.syncStatus = SyncStatus(from: event)
}
}
}
Performance: Batch Operations
- For > 100 records: use
NSBatchInsertRequest - Use
fetchBatchSizeon fetch requests (default 20) - Create compound indexes for common query patterns
- Use
NSFetchedResultsControllerfor list views
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?