Overview
Chapter uses Swift’sCodable protocol extensively for JSON serialization with Supabase. All models follow strict naming conventions and include example data for testing.
Course Models
Course_V2
The primary course data model (Course_v2.swift:12):
Course_v2.swift
Computed Category Properties
Courses decode category IDs and expose them as enums:Course_v2.swift
University Name Helper
Course_v2.swift
CodingKeys for Snake Case
Supabase uses snake_case, Swift uses camelCase:Course_v2.swift
Supporting Course Types
CourseRatings
NSSScores (National Student Survey)
GraduateOpportunities
Enums and Categories
CourseFurtherCategory
Represents subject areas (Misc.swift):
CourseOptionalCompulsory
CourseModeV2
CourseQualification
User Models
GroupUser
Represents a user profile:EnrollmentStatus
Group Models
GroupChat
GroupType
Location Models
CampusV2
City
Example Data Pattern
All models include static example data for SwiftUI previews:Course_v2.swift
Notification Models
InboxNotification
NotificationType
JSON Decoding Best Practices
Use CodingKeys for snake_case
Use CodingKeys for snake_case
Supabase uses snake_case while Swift uses camelCase. Always define
CodingKeys enum to map between them:Make optional properties truly optional
Make optional properties truly optional
Use optionals (
?) for any field that might not be present in the API response to avoid decoding errors.Provide example data
Provide example data
Always include static example instances for use in SwiftUI previews and unit tests.
Use computed properties for derived data
Use computed properties for derived data
Instead of storing redundant data, use computed properties:
Type Safety with Enums
Chapter uses enums extensively instead of raw strings/integers:- EnrollmentStatus: User journey stage
- CourseFurtherCategory: Subject classification
- GroupType: Chat group classification
- NotificationType: Notification categories
- Compile-time safety
- Exhaustive switch coverage
- Autocomplete support
- Refactoring confidence
Related Documentation
Architecture Overview
Learn how these models fit into the overall architecture
Navigation System
See how models are passed between views