IceCreamBuilder: Building an iMessage Extension
At a glance
| Item | Summary |
|---|---|
| Purpose | Allow users to collaborate on the design of ice cream sundae stickers. |
| App architecture | A Swift sample with the source-visible chain AppDelegate → BuildIceCreamViewController → Messages APIs. |
| Main patterns | View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks |
| Project style | 17 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
├── IceCreamBuilder/
│ ├── AppDelegate.swift
│ └── ViewController.swift
└── IceCreamBuilderMessagesExtension/
├── IceCreamsViewController.swift
├── BuildIceCreamViewController.swift
├── CompletedIceCreamViewController.swift
├── IceCreamPart.swift
├── IceCreamView.swift
├── MessagesViewController.swift
├── IceCream+Image.swift
├── IceCream.swift
├── IceCreamAddCell.swift
└── IceCreamCell.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 8 project/configuration file(s) and 23 source declaration(s).
Overall architecture
flowchart LR
N1["AppDelegate"]
N2["BuildIceCreamViewController"]
N3["Messages APIs"]
N1 --> N2
N2 --> N3
Reference code
IceCreamBuilder/AppDelegate.swift:10 — architecture anchor
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Messages.
Ownership and state
classDiagram
AppDelegate o-- UIWindow : window
IceCreamsViewController o-- IceCreamsViewControllerDelegate : delegate
IceCreamsViewController *-- Array : items
BuildIceCreamViewController o-- BuildIceCreamViewControllerDelegate : delegate
Ownership evidence
IceCreamBuilder/AppDelegate.swift:13 — stored dependency or nearest verified ownership anchor
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AppDelegate |
UIWindow (window) |
stores or receives | App/module collaborators |
IceCreamsViewController |
IceCreamsViewControllerDelegate (delegate) |
holds a non-owning reference | The referenced object’s lifecycle is owned elsewhere |
IceCreamsViewController |
Array (items) |
owns value state | Initialized by the owner; the binding is immutable |
BuildIceCreamViewController |
BuildIceCreamViewControllerDelegate (delegate) |
holds a non-owning reference | The referenced object’s lifecycle is owned elsewhere |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Class and protocol design
IceCreamBuilderMessagesExtension/IceCreamsViewController.swift:111 — representative type boundary
protocol IceCreamsViewControllerDelegate: AnyObject {
/// Called when a user choses to add a new `IceCream` in the `IceCreamsViewController`.
func iceCreamsViewControllerDidSelectAdd(_ controller: IceCreamsViewController)
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate |
IceCreamsViewControllerDelegate |
Defines a capability or collaboration contract | AnyObject |
BuildIceCreamViewControllerDelegate |
Defines a capability or collaboration contract | AnyObject |
IceCreamsViewController |
View lifecycle, callbacks, and feature coordination | UICollectionViewController |
BuildIceCreamViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
ViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
CompletedIceCreamViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
IceCreamView |
User-interface presentation and input forwarding | UIStackView |
MessagesViewController |
View lifecycle, callbacks, and feature coordination | MSMessagesAppViewController |
IceCreamPart |
Defines a capability or collaboration contract | Concrete collaborators/imported frameworks |
The source explicitly defines local protocol relationships: Topping → IceCreamPart, Topping → QueryItemRepresentable, Scoops → IceCreamPart, Scoops → QueryItemRepresentable, Base → IceCreamPart, Base → QueryItemRepresentable.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
iceCreamParts (IceCreamBuilderMessagesExtension/BuildIceCreamViewController.swift:38) |
fileprivate |
Use is restricted to this source file. | Inference: share with same-file helpers or extensions without exposing the symbol module-wide. |
prompt (IceCreamBuilderMessagesExtension/BuildIceCreamViewController.swift:46) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
renderParts (IceCreamBuilderMessagesExtension/IceCream+Image.swift:68) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
maximumHistorySize (IceCreamBuilderMessagesExtension/IceCreamHistory.swift:14) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
Reference code
IceCreamBuilderMessagesExtension/BuildIceCreamViewController.swift:38 — representative boundary
fileprivate var iceCreamParts = [IceCreamPart]() {
// ...
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| View lifecycle, callbacks, and feature coordination | BuildIceCreamViewController, CompletedIceCreamViewController, IceCreamsViewController, MessagesViewController |
The source’s Controller suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate, BuildIceCreamViewControllerDelegate, IceCreamsViewControllerDelegate |
The source’s Delegate suffix makes this role explicit. |
| User-interface presentation and input forwarding | IceCreamView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | IceCreamBuilderMessagesExtension/BuildIceCreamViewController.swift:10 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Protocol-oriented abstraction | IceCreamBuilderMessagesExtension/IceCreamPart.swift:20 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | IceCreamBuilder/AppDelegate.swift:11 |
Callback protocols invert event delivery back into the sample’s owner. |
Naming conventions
- Types: Controller: BuildIceCreamViewController, CompletedIceCreamViewController, IceCreamsViewController, MessagesViewController, ViewController; Delegate: AppDelegate, BuildIceCreamViewControllerDelegate, IceCreamsViewControllerDelegate; View: IceCreamView.
- Protocols:
IceCreamsViewControllerDelegate,BuildIceCreamViewControllerDelegate,IceCreamPart,QueryItemRepresentable. - Methods:
collectionView,dequeueIceCreamCell,dequeueIceCreamAddCell,iceCreamsViewControllerDidSelectAdd,viewDidLoad,viewDidLayoutSubviews,didTapSelect,buildIceCreamViewController. - Files:
IceCreamBuilder/AppDelegate.swift,IceCreamBuilderMessagesExtension/IceCreamsViewController.swift,IceCreamBuilderMessagesExtension/BuildIceCreamViewController.swift,IceCreamBuilder/ViewController.swift,IceCreamBuilderMessagesExtension/CompletedIceCreamViewController.swift,IceCreamBuilderMessagesExtension/IceCreamPart.swift.
Architecture takeaways
AppDelegateis the main source-visible entry or composition anchor for this sample.- Framework work reaches UIKit, Messages through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
IceCreamBuilder/AppDelegate.swift |
AppDelegate |
IceCreamBuilderMessagesExtension/IceCreamsViewController.swift |
IceCreamsViewController, CollectionViewItem, IceCreamsViewControllerDelegate |
IceCreamBuilderMessagesExtension/BuildIceCreamViewController.swift |
BuildIceCreamViewController, BuildIceCreamViewControllerDelegate |
IceCreamBuilder/ViewController.swift |
ViewController |
IceCreamBuilderMessagesExtension/CompletedIceCreamViewController.swift |
CompletedIceCreamViewController |
IceCreamBuilderMessagesExtension/IceCreamPart.swift |
IceCreamPart, Topping, Scoops, Base |
IceCreamBuilderMessagesExtension/IceCreamView.swift |
IceCreamView |
IceCreamBuilderMessagesExtension/MessagesViewController.swift |
MessagesViewController |
IceCreamBuilderMessagesExtension/IceCream+Image.swift |
StickerProperties |
IceCreamBuilderMessagesExtension/IceCream.swift |
IceCream |