StudentCRUD: Building a macOS Student Management System with Swift and SwiftUI
Core Technology Stack
- Language: Swift 5
- UI Framework: SwiftUI
- Database: SQLite (local storage)
- Database Driver: SQLite.swift
- Architecture: MVVM + DAO
- IDE: Xcode
System Architecture
The project uses a clear layered structure:
StudentCRUD/
├── Core/ # 核心模块
├── Database/ # 数据库管理
├── DAO/ # 数据访问对象
├── Views/ # SwiftUI视图组件
└── Models/ # 数据模型
Features
1. Multi-module Management
- Student Management: Complete CRUD operations on student records
- Teacher Management: Add, edit, delete, and view teacher information
- Course Management: Maintain course data
- Enrollment Management: Track student course registrations
- Grade Management: Record and query examination scores
2. Modern User Interface
- NavigationSplitView for sidebar-driven navigation
- Responsive design across screen sizes
- Search functionality
- Form validation on data entry
3. Data Management
- Relational SQLite schema
- Enforced data consistency
- Local storage only; no network transmission
- Full user data privacy
Technical Implementation
1. MVVM Architecture
Reactive state management using ObservableObject and @Published properties:
class StudentViewModel: ObservableObject {
@Published var students: [Student] = []
@Published var searchText: String = ""
// 响应式数据更新
func loadStudents() {
// DAO层数据获取
}
}
2. DAO Pattern
The data-access layer abstracts database logic, improving testability and maintenance:
protocol StudentDAO {
func create(_ student: Student) -> Bool
func read(id: Int) -> Student?
func update(_ student: Student) -> Bool
func delete(id: Int) -> Bool
}
3. Database Schema
A normalized relational design across five core tables:
- Students
- Teachers
- Courses
- Enrollments
- Scores
4. SwiftUI Interface
Declarative UI leveraging SwiftUI's reactive model:
NavigationSplitView {
// 侧边栏
SidebarView()
} detail: {
// 主内容区
DetailView()
}
Security Design
macOS App Sandbox
The application enables App Sandbox:
- Restricts access to system resources
- Protects user data and system integrity
- Meets Mac App Store distribution requirements
Data Privacy
- SQLite stored locally
- No external network calls
- Complete on-device data handling
Localization
The interface is fully localized to Simplified Chinese, with text adapted to Chinese educational workflows and input conventions.
Development Decisions
During development, the project structure was reorganized:
- Removed Swift Package Manager configuration
- Restructured Xcode project layout
- Grouped files by functional domain
- Improved code organization
Rationale for Architecture Choices
- MVVM: Aligns with SwiftUI's reactive programming model
- DAO: Isolates data access, enabling testing without a database
- SQLite: Lightweight relational database suitable for desktop applications
- SwiftUI: Declarative UI framework reducing boilerplate
Technical Lessons
This project demonstrated:
- Advanced SwiftUI: NavigationSplitView, Form, List, and reactive state binding
- Database Design: SQLite best practices within Swift applications
- Architecture in Practice: MVVM and DAO patterns applied to a complete application
- macOS Development: App Sandbox configuration and deployment workflow