Skip to content

ahmetbostanciklioglu/Swift-Data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

💾 Swift Data for iOS

A minimal SwiftUI + SwiftData example for persisting a simple list on-device

Platform Swift SwiftUI SwiftData Xcode Stars Last Commit

📖 Overview

Swift Data for iOS is a concise, runnable learning example that shows how to use Apple's SwiftData framework together with SwiftUI. It demonstrates the core persistence loop: defining a @Model class, wiring up a ModelContainer, querying stored records with @Query, and inserting or deleting items through the modelContext. The app itself is a single screen where you type text, press return to save it, and swipe to delete — all persisted on-device across launches.

✨ What it covers

  • Declaring a persistent model with the @Model macro (SwiftDataModel).
  • Bootstrapping a ModelContainer at the app entry point and injecting it with .modelContainer(...).
  • Reading persisted records reactively via the @Query property wrapper.
  • Inserting new records into the store using @Environment(\.modelContext) and context.insert(...).
  • Deleting records with context.delete(...) wired to SwiftUI's .onDelete swipe action.
  • Using #Preview with an in-memory model container for fast SwiftUI previews.

🚀 Getting Started

git clone https://github.com/ahmetbostanciklioglu/Swift-Data.git
cd Swift-Data
open "Swift Data for iOS.xcodeproj"

Then select an iOS 18 simulator (or a connected device) and press ⌘R to build and run.

📋 Requirements

  • iOS 18.0 or later
  • Xcode 16 or later
  • Swift 5.0

🧑‍💻 Author

Ahmet Bostancıklıoğlu@ahmetbostanciklioglu · ahmetbostancikli@gmail.com


⭐ If this helped you, consider giving the repo a star!

About

A minimal SwiftUI + SwiftData example: persist, query, and delete a list on-device (iOS 18).

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages