Ios Persistence
ASecurityUse the container that matches your persistence tier: - SwiftData on iOS 17+: configure a `ModelContainer` and keep it on the main actor. - Core Data for older apps: configure an `NSPersistentContainer`. SwiftData example: ```swift import SwiftData @Model final class Note { var title: String init(title: String) { self.title = title } } @MainActor final class PersistenceController { let container: ModelContainer init(inMemory: Bool = false) throws { let config = ModelConfiguration(isStoredInMe...
- 584 stars
- 0 votes
- 0 copies
- 2 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 11 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill ios-persistence --agent claude-codeAre you the author of Ios Persistence?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-ios-persistence-098ecc22)Use the container that matches your persistence tier:
- SwiftData on iOS 17+: configure a `ModelContainer` and keep it on the main actor.
- Core Data for older apps: configure an `NSPersistentContainer`.
SwiftData example:
```swift
import SwiftData
@Model
final class Note {
var title: String
init(title: String) {
self.title = title
}
}
@MainActor
final class PersistenceController {
let container: ModelContainer
init(inMemory: Bool = false) throws {
let config = ModelConfiguration(isStoredInMemoryOnly: inMemory)
container = try ModelContainer(for: Note.self, configurations: config)
}
}
```
Core Data example:
```swift
import CoreData
final class PersistenceController {
static let shared = PersistenceController()
let container: NSPersistentContainer
init(inMemory: Bool = false) {
container = NSPersistentContainer(name: "MyModel")
if inMemory {
container.persistentStoreDescriptions.first?.url = URL(fileURLWithPath: "/dev/null")
}
container.loadPersistentStores { _, error in
if let error = error {
fatalError("Failed to load store: \(error)")
}
}
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
container.viewContext.automaticallyMergesChangesFromParent = true
}
}
```
Good defaults:
- Use SwiftData for new iOS 17+ apps.
- Keep SwiftData container setup on `@MainActor`.
- For Core Data, set an explicit merge policy.
- Do heavy writes in a background context with `newBackgroundContext()`, not on `viewContext`.
- Store secrets like tokens in secure storage, not `UserDefaults`.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.