我做了一个基于 Core Data 的离线记账应用 LedgerBox,包含账户、分类、交易三大核心实体,通过 relationship 建模它们的关联。交易列表使用 NSFetchedResultsController 实现自动刷新,并支持筛选和排序。统计页实现了按时间范围汇总收入、支出和分类排行,同时我还做了后台 context 的批量数据插入和一次轻量级迁移,完整覆盖了 Core Data 的常见工程场景。
- 账户管理:支持添加、编辑、删除账户。
- 分类管理:支持添加、编辑、删除分类。
- 交易管理:支持添加、编辑、删除交易。
- 交易筛选与排序:按日期、金额、分类等筛选和排序交易。
- 统计分析:按时间范围汇总收入、支出和分类排行。
- 后台批量生成测试数据:快速生成模拟数据。
- Core Data 多实体关系建模:账户、分类、交易三大核心实体。
- NSFetchedResultsController:实现列表自动刷新。
- Lightweight Migration:支持轻量级数据迁移。
- 使用 Repository 模式 隔离 UI 与持久化层。
- 使用 NSFetchedResultsController 实现列表自动刷新。
- 使用后台 NSManagedObjectContext 进行批量插入。
- 使用 Core Data relationship 建模账户、分类、交易。
- 实现时间范围统计与分类聚合。
- 支持 Lightweight Migration。
LedgerBox/
├── AppDelegate.h/m
├── SceneDelegate.h/m
├── ViewController.h/m
├── Assets.xcassets/
├── Base.lproj/
│ ├── LaunchScreen.storyboard
│ ├── Main.storyboard
├── LedgerBox.xcdatamodeld/
│ ├── LedgerBox.xcdatamodel/
│ ├── LedgerBoxV2.xcdatamodel/
├── Persistence/
│ ├── CoreDataManager.h/m
│ ├── SampleDataGenerator.h/m
│ ├── Repository/
│ ├── AccountRepository.h/m
│ ├── CategoryRepository.h/m
│ ├── StatisticsRepository.h/m
│ ├── TransactionRepository.h/m
├── UI/
│ ├── Base/
│ │ ├── AccountListViewController.h/m
│ │ ├── AddTransactionViewController.h/m
│ │ ├── CategoryListViewController.h/m
│ │ ├── StatisticsViewController.h/m
│ │ ├── TransactionListViewController.h/m
│ ├── Components/
├── Utils/
│ ├── LBFormatterProvider.h/m
│ ├── UIViewController+LBAlert.h/m
- Xcode 版本:14.0 或更高。
- iOS 版本:支持 iOS 15.0 及以上。
- 运行步骤:
- 克隆项目到本地。
- 使用 Xcode 打开
LedgerBox.xcodeproj。 - 选择模拟器或真机运行。



