Lists: Retaining User Data with Persistent Storage
Master iOS Data Persistence with UserDefaults Storage
Core Learning Objectives
Persistent Storage Implementation
Learn to retain user data between app sessions using UserDefaults. Convert class-based data to simple types for storage compatibility.
Data Module Architecture
Create app-wide accessible data modules. Structure code for maintainability and separation of concerns in Swift projects.
UI State Management
Master checkbox state retention and table view cell reuse patterns. Sync user interface with persistent storage effectively.
Classes cannot be exported directly to persistent storage because different systems implement classes differently. All data must be converted to simple types like dictionaries and arrays.
UserDefaults Storage Approach
Prerequisites Verification
Essential foundation for understanding data flow and UI components
Ensure all required files are accessible in separate editor tabs
Main.storyboard, Data Model.swift, ListsVC.swift, ListItemsVC.swift, ListItemTVCell.swift
Table View Cells get queued and reused for performance. When cells enter the queue, all specific data is forgotten. Never rely on cells to store boolean states like checked/unchecked status.
Fix Checkbox State Loss
Copy Button Image Code
Extract the setImage method from checkButtonTapped in ListItemTVCell.swift
Add to cellForRowAt Method
Paste and modify code in ListItemsVC.swift cellForRowAt method with proper cell references
Test State Retention
Navigate between screens to verify checkbox states persist during app session
Rename Data Model.swift to Data Module.swift when expanding beyond simple models. This reflects the file's broader responsibility for data management and storage operations.
Essential Data Module Methods
loadLists Method
Retrieves data from persistent storage and converts simple types back into List and ListItem class instances for the app to use.
saveLists Method
Converts class-based data into simple types and saves changes to persistent storage when lists or items are modified.
Key Takeaways

next to one of the items to mark it as completed.
have disappeared. The app has failed to retain the checked/unchecked state of the items.