Did you know Apple provides Sample Code? I learned App Architecture from Apple’s Sample Projects.
In this post, I drew the high level diagram of the Apple’s Sample Code.
Check Apple’s Sample Code

Visit Apple Developer’s site and filter by Sample Code
https://developer.apple.com/documentation/uikit
Project 1. Restoring Your App’s State

https://developer.apple.com/documentation/uikit/uiscenedelegate/restoring_your_app_s_state
This sample project demonstrates how to preserve your appʼs state information and restore the app to that previous state on subsequent launches. During a subsequent launch, restoring your interface to the previous interaction point provides continuity for the user, and lets them finish active tasks quickly.
When using your app, the user performs actions that affect the user interface. For example, the user might view a specific page of information, and after the user leaves the app, the operating system might terminate it to free up the resources it holds. The user should be able to return to where they left off — and UI state restoration is a core part of making that experience seamless.
This sample app demonstrates the use of state preservation and restoration for scenarios where the system interrupts the app. The sample project manages a set of products. Each product has a title, an image, and other metadata you can view and edit. The project shows how to preserve and restore a product in its DetailParentViewController.
The sample supports two state preservation approaches. In iOS 13 and later, apps save the state for each window scene using NSUserActivity objects. In iOS 12 and earlier, apps preserve the state of their user interfaces by saving and restoring the configuration of view controllers.
For scene-based apps, UIKit asks each scene to save its state information using an NSUserActivity object. NSUserActivity is a core part of modern state restoration with UIScene and UISceneDelegate. In your own apps, you use the activity object to store information needed to recreate your scene’s interface and restore the content of that interface. If your app doesn’t support scenes, use the view-controller-based state restoration process to preserve the state of your interface instead.
By Apple
High Level System Design

It uses Singleton DataModelManager.
All the ViewControllers access singleton DataModelManager directly to get data.
The logics are focused on how to save and restore the states using UIStateRestoring.
🌟 Interesting points
- It has two scenes.
- Main Scene
- Image Scene
- AppDelegate handles where user navigate to the scene by checking NSUserActivity
Project Folder structures

Project 2. Supporting Multiple Windows on iPad

https://developer.apple.com/documentation/uikit/uiscenedelegate/supporting_multiple_windows_on_ipad

This project is very simple. Most of the functions are belong to ViewController.
Learned from this project
- UICollectionViewCell’s reuseIdentifier is declared in PhotoCell.
- static reuseIdentifier
- Function names
- initialize the UI codes -> func configure()
- initialize the storyboard -> loadFromStoryboard()
- Class / Struct name
- I found Apple’s sample codes usually naming the noun + manager for class / struct.
- PhotoManager
- I found Apple’s sample codes usually naming the noun + manager for class / struct.
- Conveniently use Static / Singletons
- UserActivity has multiple static properties

Project 3. Supporting desktop-class features in your iPad app





Leave a comment