Article · 2025-07-23

StudentCRUD: Building a macOS Student Management System with Swift and SwiftUI

Core Technology Stack

System Architecture

The project uses a clear layered structure:

StudentCRUD/
├── Core/                    # 核心模块
├── Database/               # 数据库管理
├── DAO/                   # 数据访问对象
├── Views/                 # SwiftUI视图组件
└── Models/                # 数据模型

Features

1. Multi-module Management

2. Modern User Interface

3. Data Management

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:

4. SwiftUI Interface

Declarative UI leveraging SwiftUI's reactive model:

NavigationSplitView {
    // 侧边栏
    SidebarView()
} detail: {
    // 主内容区
    DetailView()
}

Security Design

macOS App Sandbox

The application enables App Sandbox:

Data Privacy

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:

Rationale for Architecture Choices

  1. MVVM: Aligns with SwiftUI's reactive programming model
  2. DAO: Isolates data access, enabling testing without a database
  3. SQLite: Lightweight relational database suitable for desktop applications
  4. SwiftUI: Declarative UI framework reducing boilerplate

Technical Lessons

This project demonstrated:

  1. Advanced SwiftUI: NavigationSplitView, Form, List, and reactive state binding
  2. Database Design: SQLite best practices within Swift applications
  3. Architecture in Practice: MVVM and DAO patterns applied to a complete application
  4. macOS Development: App Sandbox configuration and deployment workflow
© 2026 Yuxu Ge ·