Core Data for Swift is a compact iOS sample app that demonstrates how to persist data locally with Apple's Core Data framework in a SwiftUI app. It stores simple text items on device, lists them, and lets you delete them — all wired together with a clean MVVM structure. The project is a focused reference for the essential Core Data building blocks: a persistent container stack, a managed object model, @FetchRequest, and saving/deleting through a ViewModel.
- Persist text items to disk via an
NSPersistentContainer-backedCoreDataStacksingleton. - Live-updating list of saved entities using SwiftUI's
@FetchRequestwith a sort descriptor and animation. - Add on submit — type into a text field and press return to save a new
ModelEntity(with a generatedUUID). - Swipe to delete items, with the delete persisted back to the managed object context.
- MVVM separation — the
ViewModelowns save logic (includingrollback()on failure), keeping the view declarative. - Safe optionals — an
Optional<String>extension unwraps Core Data's optionaltextattribute to a non-optionalString.
git clone https://github.com/ahmetbostanciklioglu/Core-Data.git
cd Core-Data
open "Core Data for Swift.xcodeproj"Then open the project in Xcode and press ⌘R to build and run on a simulator or device.
- iOS 18.0 or later
- Xcode 16 or later
- Swift 5.0
Ahmet Bostancıklıoğlu — @ahmetbostanciklioglu · ahmetbostancikli@gmail.com
⭐ If this helped you, consider giving the repo a star!