一键导入
swift-data
SwiftData persistence framework with models, queries, relationships, and CloudKit sync
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
SwiftData persistence framework with models, queries, relationships, and CloudKit sync
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Comprehensive iOS development guidance covering SwiftUI, Swift Concurrency, Core Data, and Swift Testing
SQLiteData persistence library (Point-Free) - a fast SwiftData alternative using SQLite/GRDB. Use when working with SQLiteData, GRDB, type-safe SQL queries, @Table macro, @FetchAll/@FetchOne property wrappers, or migrating from SwiftData to SQLite-based persistence.
Technical blog writing with engaging hooks, progressive complexity, and code-first explanations
Comprehensive code review for quality, security, performance, and best practices across any language
Designs comprehensive implementation plans for new features with architecture considerations
Creates distinctive, production-grade frontend interfaces with high design quality, avoiding generic AI aesthetics
| name | swift_data |
| description | SwiftData persistence framework with models, queries, relationships, and CloudKit sync |
You are a SwiftData expert. Apply these patterns when working with data persistence in Swift apps.
| Need | Reference |
|---|---|
| Define models and properties | → model-basics.md |
| Create relationships between models | → relationships.md |
| Query, filter, and sort data | → queries-filtering.md |
| Configure containers and contexts | → containers-contexts.md |
| Enable iCloud sync | → cloudkit-sync.md |
| Handle schema migrations | → migration.md |
| Optimize performance | → performance.md |
| Debug and troubleshoot | → common-issues.md |
import SwiftData
@Model
final class Book {
var title: String
var author: String
var publishedDate: Date
var rating: Int?
init(title: String, author: String, publishedDate: Date) {
self.title = title
self.author = author
self.publishedDate = publishedDate
}
}
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(for: Book.self)
}
}
struct BookList: View {
@Query(sort: \Book.title) var books: [Book]
@Environment(\.modelContext) var modelContext
var body: some View {
List(books) { book in
Text(book.title)
}
}
}
// Create
let book = Book(title: "Swift Guide", author: "Apple", publishedDate: .now)
modelContext.insert(book)
// Read - use @Query or fetch
let descriptor = FetchDescriptor<Book>(
predicate: #Predicate { $0.rating ?? 0 > 3 },
sortBy: [SortDescriptor(\.title)]
)
let books = try modelContext.fetch(descriptor)
// Update - modify properties directly
book.title = "Updated Title"
// Delete
modelContext.delete(book)
For comprehensive SwiftData tutorials, check Hacking with Swift - SwiftData.