<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>How Apple&apos;s Frameworks Work</title>
<link>https://aleahim.com/</link>
<description>SwiftUI and Core Animation, looked at underneath and measured against the real framework.</description>
<language>en-US</language>
<atom:link href="https://aleahim.com/collections/frameworks/feed.xml" rel="self" type="application/rss+xml"/>
<item>
<title>SwiftUI Doesn&apos;t Have a List. It Wraps Someone Else&apos;s.</title>
<link>https://aleahim.com/blog/swiftui-has-no-list/</link>
<guid isPermaLink="true">https://aleahim.com/blog/swiftui-has-no-list/</guid>
<pubDate>Mon, 23 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>A SwiftUI List looks like a SwiftUI thing. I looked underneath, on the Mac, an iPhone and an iPad, and what is running is a table view or a collection view from the platform, with SwiftUI&apos;s own cells and diffing on top. Here is what is there, what SwiftUI does with it, and what it costs.</description>
<content:encoded><![CDATA[<h1>SwiftUI Doesn’t Have a List. It Wraps Someone Else’s.</h1>
<p>I wrote <code>List</code>, and a list appeared. It scrolled, it recycled its rows, it animated an insert. So I assumed SwiftUI had built a list.</p>
<p>It has not. What is on the screen is a container that was there long before SwiftUI: a table view on the Mac, a collection view on the iPhone and the iPad. SwiftUI puts its own cells and its own change detection on top, and hands the platform container the rest of the work. This is not a secret. It is just not what the word <code>List</code> makes you picture. Here is the whole stack, from your code down to the platform:</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart TB
  A[&quot;Your code: List { ... }&quot;] --&gt; B[&quot;SwiftUI: diff, rows, timing&quot;]
  B --&gt; C[&quot;One hosting view per row&quot;]
  C --&gt; D([&quot;Mac: NSOutlineView&quot;])
  C --&gt; E([&quot;iPhone and iPad: UICollectionView&quot;])
  classDef platform fill:#10335c,stroke:#4a9eff,stroke-width:3px,color:#ffffff
  class D,E platform
</pre>
</figure>
<p><em>What a List is made of: three layers are SwiftUI’s, the container at the bottom is not.</em></p>
<p>I found it out because I was building a forum of my own, with long lists in it, and I had been told that a collection view is much faster than a SwiftUI List. I had no number behind that. So I measured, and to measure honestly I first had to know what I was measuring. This post is the first half of that story: what is under a <code>List</code>, how I know, what SwiftUI adds, and what that does to the cost of a change. The full measurements are in a longer article I am publishing next, and the code and raw data are public now: the link is at the end.</p>
<h2>How I looked</h2>
<p>I did not read this anywhere. I read it from the running app, two ways that share no code: with the Objective-C runtime, whose public functions can name the class of any object in the view tree, and with the layers of the live app through my own XRay Viewer, which reads the delegate of every layer. A layer’s own class says little (<code>NSViewBackingLayer</code> on the Mac, <code>CALayer</code> on iOS), but its delegate usually says what the object is. When the two readings give the same class names, I believe them.</p>
<p>Before I trusted either reading on a <code>List</code>, I pointed it at a plain <code>NSTableView</code> and a plain <code>UICollectionView</code> whose behaviour I drive myself. If the probe cannot get a known answer right, its answer on the unknown is worth nothing.</p>
<figure class="td-term"><div class="td-term-bar"><span class="td-term-dots" aria-hidden="true"></span><span class="td-term-title">What a List is</span></div><pre class="td-term-body"><code><span class="td-term-b">Mac</span>
  <span class="td-term-c6">SwiftUIOutlineListView</span>
  <span class="td-term-d">subclass of</span> NSOutlineView
  <span class="td-term-d">subclass of</span> NSTableView

<span class="td-term-b">iPhone and iPad</span>
  <span class="td-term-c6">UpdateCoalescingCollectionView</span>
  <span class="td-term-d">subclass of</span> UICollectionView</code></pre></figure>

<p><em>Not an opinion: the runtime’s own answer, one line per platform.</em></p>
<h2>What is underneath</h2>
<p>On the Mac, a <code>List</code> is a <code>SwiftUIOutlineListView</code>. It is a subclass of <code>NSOutlineView</code>, which is itself a subclass of <code>NSTableView</code>, so the Mac <code>List</code> is a table view. It sits in a scroll view with its own clip view, it has one column, and automatic row heights are on. Each live row is a <code>ListTableRowView</code> holding a <code>ListTableCellView</code>, which holds one hosting view with your SwiftUI row inside. Apple’s own page for <code>NSOutlineView</code> says that subclassing it is not recommended, which is a nice detail next to a subclass that SwiftUI makes.</p>
<p>On the iPhone, a <code>List</code> is an <code>UpdateCoalescingCollectionView</code>. That is a <code>UICollectionView</code>, with a compositional layout, and its cells are <code>ListCollectionViewCell</code>, a <code>UICollectionViewListCell</code>. The cell’s own content configuration is empty. The content is a hosting view that holds your SwiftUI row. The simulator, a real iPhone and a real iPad agree on every class.</p>
<ul class="td-landing td-landing-cards td-landing-cards-3" role="list">
<li class="td-landing-card">
<p class="td-landing-card-badge">A table view</p>
<h3 class="td-landing-card-title">Mac</h3>
<p class="td-landing-card-body">An outline view, which is a table view. A hosting view in every row.</p>
</li>
<li class="td-landing-card">
<p class="td-landing-card-badge">A collection view</p>
<h3 class="td-landing-card-title">iPhone</h3>
<p class="td-landing-card-body">SwiftUI’s own subclass of it. A hosting view in every cell.</p>
</li>
<li class="td-landing-card">
<p class="td-landing-card-badge">A collection view</p>
<h3 class="td-landing-card-title">iPad</h3>
<p class="td-landing-card-body">The same one as the iPhone, reached by a slightly different route.</p>
</li>
</ul>
<p><em>Three platforms, two containers, no <code>UITableView</code> anywhere.</em></p>
<p>The data source and the delegate are one object of SwiftUI’s own in both places: <code>OutlineListCoordinator</code> on the Mac, <code>UICollectionViewListCoordinator</code> on iOS. The iOS one is not a <code>UICollectionViewDiffableDataSource</code>. SwiftUI does its own diffing and talks to the container directly.</p>
<p>A <code>Table</code> is the same story, only more so. On the Mac it is an outline view too, <code>SwiftUIOutlineTableView</code>, with a header view and two hosting views per row in my two-column probe, one per column. On iOS it is the same collection view class as <code>List</code>, with its own cell type, one hosting view per row for all the columns. In a compact width, Apple’s documentation says a <code>Table</code> hides its headers and every column after the first, which is why one cell per row is enough on a phone.</p>
<p>There is no <code>UITableView</code> anywhere in an iOS tree. And SwiftUI has no collection view of its own that you can reach: the one under a <code>List</code> is created and kept by SwiftUI, and what you get is the <code>List</code>.</p>
<h2>What SwiftUI does add</h2>
<p>It would be unfair to say it adds nothing. Three things are clearly SwiftUI’s.</p>
<p>The first is the rows. Only the rows on screen have views, at 100 rows or 100,000: 38 row views on the Mac in a 900 point window and 16 cells on an iPhone screen, in my runs. Making only what is visible is something a table view and a collection view have always done, so recycling is the platform’s. What lives in each cell is yours, hosted by SwiftUI. Apple’s words for it: an outline view “retrieves only the data that needs to be displayed”, and a <code>List</code> made from a collection “computes its rows on demand”.</p>
<figure class="td-chart td-chart-bar">
<figcaption class="td-chart-caption">Row views alive, 100 rows or 100,000</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="Row views alive, 100 rows or 100,000"
>
<desc>bar chart with 2 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="232.5"
  x2="696"
  y2="232.5"
></line>
<text
  class="td-chart-value"
  x="70"
  y="236.5"
  text-anchor="end"
>10</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="163"
  x2="696"
  y2="163"
></line>
<text
  class="td-chart-value"
  x="70"
  y="167"
  text-anchor="end"
>20</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="93.5"
  x2="696"
  y2="93.5"
></line>
<text
  class="td-chart-value"
  x="70"
  y="97.5"
  text-anchor="end"
>30</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>40</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<rect
  class="td-chart-bar td-chart-series-0"
  x="200"
  y="37.9"
  width="32"
  height="264.1"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="508"
  y="37.9"
  width="32"
  height="264.1"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="234"
  y="190.8"
  width="32"
  height="111.2"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="542"
  y="190.8"
  width="32"
  height="111.2"
  rx="4"
></rect>
<text
  class="td-chart-label"
  x="234"
  y="324"
  text-anchor="middle"
>100 rows</text>
<text
  class="td-chart-label"
  x="542"
  y="324"
  text-anchor="middle"
>100k rows</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>List size</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>Row views alive</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>Mac</text>
<rect
  class="td-chart-series-1"
  x="148.32"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="166.32"
  y="346"
  text-anchor="start"
>iPhone</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Mac, 100 rows: 38</title>
<rect class="td-chart-hit" x="200" y="37.9" width="32" height="264.1"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="137.3" y="310" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="146.3" y="330">Mac, 100 rows: 38</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Mac, 100k rows: 38</title>
<rect class="td-chart-hit" x="508" y="37.9" width="32" height="264.1"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="441.2" y="310" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="450.2" y="330">Mac, 100k rows: 38</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>iPhone, 100 rows: 16</title>
<rect class="td-chart-hit" x="234" y="190.8" width="32" height="111.2"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="159" y="152.8" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="168" y="172.8">iPhone, 100 rows: 16</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>iPhone, 100k rows: 16</title>
<rect class="td-chart-hit" x="542" y="190.8" width="32" height="111.2"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="462.9" y="152.8" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="471.9" y="172.8">iPhone, 100k rows: 16</text>
</g>
</g>
</svg>
</div>
</figure>
<p><em>100 rows or 100,000: the same number of views.</em></p>
<p>There is a second number that says the same thing from another side. When the Mac list first appears, the table asks SwiftUI for the height of 100 rows at 100 rows, and then for 301 at 1,000, at 10,000 and at 100,000. Every answer SwiftUI gives is the same: no height, which leaves it to the table’s automatic row heights. I read the count. I did not read why it is 301, and it looks like a constant of the table, not a number SwiftUI chooses.</p>
<p>The second thing is the diff. When your data changes, SwiftUI works out what changed with its own code, and sends the container the smallest set of structural calls it can. I hooked the container and wrote down every call, on a list of 1,000 rows:</p>
<table><thead><tr><th>What changed</th><th>What the container was told</th></tr></thead><tbody><tr><td>Append 50 rows</td><td>One insert of exactly those 50 indexes (1000 to 1049 on the Mac)</td></tr><tr><td>Delete one row</td><td>One remove of one index</td></tr><tr><td>Move row 500 to the front</td><td>One move</td></tr><tr><td>Replace every row with new identities</td><td>One remove and one insert</td></tr><tr><td>A row changes and keeps its place</td><td>No reload. On the Mac an empty insert and an empty remove inside the update, on iPhone no call at all</td></tr></tbody></table>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart TB
  A[&quot;Your data changes&quot;] --&gt; B[&quot;SwiftUI works out&lt;br/&gt;the difference&quot;]
  B --&gt; C[&quot;Insert, delete or move:&lt;br/&gt;one call to the container&quot;]
  B --&gt; F([&quot;Row kept its place:&lt;br/&gt;no reload at all&quot;])
  classDef surprise fill:#10335c,stroke:#4a9eff,stroke-width:3px,color:#ffffff
  class F surprise
</pre>
</figure>
<p><em>The last arrow is the surprising one: a changed row that keeps its place is never reloaded.</em></p>
<p>That last row of the table is my favourite finding. I put hooks on <code>reloadData</code>, <code>reloadItem</code> and the other reload calls of the container, changed one row, and then a tenth of the rows, and the hooks recorded nothing. The row still refreshed, so the refresh travels another way, through SwiftUI’s own graph updating the hosting view. I can show that the container is not told. That the graph does it is my reading, not something I hooked. And there is a contrast with UIKit worth a sentence: its own advice for a hand-built list is to reconfigure existing cells instead of reloading them, for performance. SwiftUI’s <code>List</code> goes one step further on the container side and tells the collection view nothing.</p>
<p>The third thing is timing. The diff does not run when you assign the new data. It runs at the end of the run loop turn, from an observer of SwiftUI’s own on the Mac and in the simulator, and through UIKit’s update cycle on a real device. If you ever time a <code>List</code>, stop the clock after the run loop has finished its turn, not when your assignment returns.</p>
<p>So the honest picture is neither “SwiftUI has no list” nor “SwiftUI is just UIKit”. It is a layer that drives the platform’s list and decides, very carefully, what to tell it.</p>
<h2>Why it matters: the container decides the costs</h2>
<p>I said I had heard a collection view is much faster. Here is the first place that is true. Updating a row you can see, a collection view that touches the visible cell and tells the layout nothing needs about a third of a millisecond, at any list size. The <code>List</code> needs 2.6 to 16.5.</p>
<figure class="td-chart td-chart-bar">
<figcaption class="td-chart-caption">Updating one visible row</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="Updating one visible row"
>
<desc>bar chart with 3 labels and 1 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="232.5"
  x2="696"
  y2="232.5"
></line>
<text
  class="td-chart-value"
  x="70"
  y="236.5"
  text-anchor="end"
>5</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="163"
  x2="696"
  y2="163"
></line>
<text
  class="td-chart-value"
  x="70"
  y="167"
  text-anchor="end"
>10</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="93.5"
  x2="696"
  y2="93.5"
></line>
<text
  class="td-chart-value"
  x="70"
  y="97.5"
  text-anchor="end"
>15</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>20</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<rect
  class="td-chart-bar td-chart-series-0"
  x="165.67"
  y="297.41"
  width="32"
  height="4.59"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="371"
  y="265.86"
  width="32"
  height="36.14"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="576.33"
  y="72.65"
  width="32"
  height="229.35"
  rx="4"
></rect>
<text
  class="td-chart-label"
  x="182.67"
  y="324"
  text-anchor="middle"
>Collection view by hand (0.33)</text>
<text
  class="td-chart-label"
  x="388"
  y="324"
  text-anchor="middle"
>List best case (2.6)</text>
<text
  class="td-chart-label"
  x="593.33"
  y="324"
  text-anchor="middle"
>List worst case (16.5)</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>How the list is fed</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>Milliseconds</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>Milliseconds</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Collection view by hand (0.33): 0.33</title>
<rect class="td-chart-hit" x="165.67" y="283.71" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="25.07" y="259.41" width="313.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="34.07" y="279.41">Collection view by hand (0.33): 0.33</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>List best case (2.6): 2.6</title>
<rect class="td-chart-hit" x="371" y="265.86" width="32" height="36.14"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="275.5" y="227.86" width="223" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="284.5" y="247.86">List best case (2.6): 2.6</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>List worst case (16.5): 16.5</title>
<rect class="td-chart-hit" x="576.33" y="72.65" width="32" height="229.35"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="468.4" y="34.65" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="477.4" y="54.65">List worst case (16.5): 16.5</text>
</g>
</g>
</svg>
</div>
</figure>
<p><em>Same job, different feed. The 0.33 is “about a third of a millisecond”, as measured; the two List figures are the ends of the measured range.</em></p>
<p>But I did not trust that number until I knew where the time went, and that needed two controls, the experiments that take one suspect away at a time.</p>
<p>The first control is a collection view whose cells are SwiftUI rows, the very row the <code>List</code> shows. If SwiftUI’s hosting were the cost, that would behave like the <code>List</code>. It behaves like my own collection view, in every operation, within the same ranges.</p>
<p>The second control is a plain <code>NSTableView</code>, the container the Mac <code>List</code> sits on, fed by hand with no SwiftUI at all. It shows 100,000 rows in 39.7 milliseconds. The <code>List</code> shows them in 39.6. Same time. So SwiftUI’s container is not what makes a long list slow to show.</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart TB
  Q[&quot;Why is the List&lt;br/&gt;slower at a change?&quot;] --&gt; A[&quot;Is the container slow?&lt;br/&gt;No: 39.7 ms by hand,&lt;br/&gt;39.6 ms in a List&quot;]
  A --&gt; B[&quot;Are SwiftUI&#39;s cells slow?&lt;br/&gt;No: same as my own cells&quot;]
  B --&gt; C([&quot;What is left:&lt;br/&gt;the feed, SwiftUI&#39;s own diff&quot;])
  classDef answer fill:#10335c,stroke:#4a9eff,stroke-width:3px,color:#ffffff
  class C answer
</pre>
</figure>
<p><em>Remove the suspects one at a time and the feed is what remains.</em></p>
<p>What is left is the feed. At 100,000 one-line rows on the Mac, in milliseconds:</p>
<table><thead><tr><th></th><th>Collection view, my cells</th><th>Collection view, SwiftUI cells</th><th><code>NSTableView</code>, fed by hand</th><th>SwiftUI List</th></tr></thead><tbody><tr><td>show the list</td><td>1,468</td><td>1,462</td><td>39.7</td><td>39.6</td></tr><tr><td>append 50 rows</td><td>1,457</td><td>1,446</td><td>0.67</td><td>18.1</td></tr><tr><td>update one row</td><td>1,466</td><td>1,461</td><td>0.53</td><td>17.3</td></tr><tr><td>one screen of scrolling</td><td>754</td><td>752</td><td>5.7</td><td>1.3</td></tr></tbody></table>
<figure class="td-chart td-chart-bar">
<figcaption class="td-chart-caption">What the feed costs at 100,000 rows</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="What the feed costs at 100,000 rows"
>
<desc>bar chart with 2 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="232.5"
  x2="696"
  y2="232.5"
></line>
<text
  class="td-chart-value"
  x="70"
  y="236.5"
  text-anchor="end"
>5</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="163"
  x2="696"
  y2="163"
></line>
<text
  class="td-chart-value"
  x="70"
  y="167"
  text-anchor="end"
>10</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="93.5"
  x2="696"
  y2="93.5"
></line>
<text
  class="td-chart-value"
  x="70"
  y="97.5"
  text-anchor="end"
>15</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>20</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<rect
  class="td-chart-bar td-chart-series-0"
  x="200"
  y="292.69"
  width="32"
  height="9.31"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="508"
  y="294.63"
  width="32"
  height="7.37"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="234"
  y="50.41"
  width="32"
  height="251.59"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="542"
  y="61.53"
  width="32"
  height="240.47"
  rx="4"
></rect>
<text
  class="td-chart-label"
  x="234"
  y="324"
  text-anchor="middle"
>Append 50 rows</text>
<text
  class="td-chart-label"
  x="542"
  y="324"
  text-anchor="middle"
>Update one row</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>Operation</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>Milliseconds</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>NSTableView fed by hand</text>
<rect
  class="td-chart-series-1"
  x="310.56"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="328.56"
  y="346"
  text-anchor="start"
>SwiftUI List</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>NSTableView fed by hand, Append 50 rows: 0.67</title>
<rect class="td-chart-hit" x="200" y="281.34" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="22.5" y="254.69" width="387" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="31.5" y="274.69">NSTableView fed by hand, Append 50 rows: 0.67</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>NSTableView fed by hand, Update one row: 0.53</title>
<rect class="td-chart-hit" x="508" y="282.32" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="329" y="256.63" width="387" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="338" y="276.63">NSTableView fed by hand, Update one row: 0.53</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI List, Append 50 rows: 18.1</title>
<rect class="td-chart-hit" x="234" y="50.41" width="32" height="251.59"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="101.6" y="12.41" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="110.6" y="32.41">SwiftUI List, Append 50 rows: 18.1</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI List, Update one row: 17.3</title>
<rect class="td-chart-hit" x="542" y="61.53" width="32" height="240.47"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="409.6" y="23.53" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="418.6" y="43.53">SwiftUI List, Update one row: 17.3</text>
</g>
</g>
</svg>
</div>
</figure>
<p><em>The same table view, fed by hand or by SwiftUI: the container does not change, the cost per change does.</em></p>
<p>Read the table in pairs. The two collection view columns are the same, so the cells are not the cost. The two columns on the right show the same container fed two ways, and it takes SwiftUI about 18 milliseconds at 100,000 rows to do what a hand-fed table does in well under one. At 10,000 rows the same update costs the <code>List</code> 4.7. So what SwiftUI adds per change grows with the list. Why, I did not measure. A cost proportional to the number of rows in its diff would look like this, and that is a guess.</p>
<p>And the table is not better at everything. One screen of scrolling takes the hand-fed table 5.7 milliseconds and the <code>List</code> 1.3. The <code>List</code> is not slow. It is a particular trade.</p>
<h2>Where the self-sizing collection view loses</h2>
<p>The collection view columns of that table, 1,468 milliseconds to show the list, are the biggest numbers in this post, and they are not about SwiftUI at all. They belong to a collection view that measures its own rows, using estimated heights. Appending 50 rows to it, in milliseconds:</p>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">Appending 50 rows as the list grows</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 404"
  role="img"
  aria-label="Appending 50 rows as the list grows"
>
<desc>line chart with 4 labels and 3 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="209.33"
  x2="696"
  y2="209.33"
></line>
<text
  class="td-chart-value"
  x="70"
  y="213.33"
  text-anchor="end"
>500</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="116.67"
  x2="696"
  y2="116.67"
></line>
<text
  class="td-chart-value"
  x="70"
  y="120.67"
  text-anchor="end"
>1000</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>1500</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<polyline class="td-chart-line td-chart-series-0" points="157,300.22 311,300.02 465,294.59 619,33.45"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="157"
  cy="300.22"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="311"
  cy="300.02"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="465"
  cy="294.59"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="619"
  cy="33.45"
  r="4"
></circle>
<polyline class="td-chart-line td-chart-series-1" points="157,300.89 311,301.02 465,301 619,300.85"></polyline>
<circle
  class="td-chart-point td-chart-series-1"
  cx="157"
  cy="300.89"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="311"
  cy="301.02"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="465"
  cy="301"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="619"
  cy="300.85"
  r="4"
></circle>
<polyline class="td-chart-line td-chart-series-2" points="157,301.44 311,301.35 465,301.11 619,298.85"></polyline>
<circle
  class="td-chart-point td-chart-series-2"
  cx="157"
  cy="301.44"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-2"
  cx="311"
  cy="301.35"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-2"
  cx="465"
  cy="301.11"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-2"
  cx="619"
  cy="298.85"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="157"
  y="324"
  text-anchor="middle"
>100</text>
<text
  class="td-chart-label"
  x="311"
  y="324"
  text-anchor="middle"
>1000</text>
<text
  class="td-chart-label"
  x="465"
  y="324"
  text-anchor="middle"
>10000</text>
<text
  class="td-chart-label"
  x="619"
  y="324"
  text-anchor="middle"
>100000</text>
<text
  class="td-chart-label"
  x="388"
  y="390"
  text-anchor="middle"
>Rows in the list</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>Milliseconds</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>Collection view, rows measure themselves</text>
<rect
  class="td-chart-series-1"
  x="80"
  y="358"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="368"
  text-anchor="start"
>Collection view, one fixed height</text>
<rect
  class="td-chart-series-2"
  x="362.88"
  y="358"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="380.88"
  y="368"
  text-anchor="start"
>SwiftUI List</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Collection view, rows measure themselves, 100: 9.6</title>
<circle class="td-chart-hit" cx="157" cy="300.22" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="4" y="258.22" width="428" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="13" y="278.22">Collection view, rows measure themselves, 100: 9.6</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Collection view, rows measure themselves, 1000: 10.7</title>
<circle class="td-chart-hit" cx="311" cy="300.02" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="88.8" y="258.02" width="444.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="97.8" y="278.02">Collection view, rows measure themselves, 1000: 10.7</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Collection view, rows measure themselves, 10000: 40</title>
<circle class="td-chart-hit" cx="465" cy="294.59" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="246.9" y="252.59" width="436.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="255.9" y="272.59">Collection view, rows measure themselves, 10000: 40</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Collection view, rows measure themselves, 100000: 1449</title>
<circle class="td-chart-hit" cx="619" cy="33.45" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="255.2" y="45.45" width="460.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="264.2" y="65.45">Collection view, rows measure themselves, 100000: 1449</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>Collection view, one fixed height, 100: 6</title>
<circle class="td-chart-hit" cx="157" cy="300.89" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="4" y="258.89" width="354.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="13" y="278.89">Collection view, one fixed height, 100: 6</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>Collection view, one fixed height, 1000: 5.3</title>
<circle class="td-chart-hit" cx="311" cy="301.02" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="121.6" y="259.02" width="378.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="130.6" y="279.02">Collection view, one fixed height, 1000: 5.3</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>Collection view, one fixed height, 10000: 5.4</title>
<circle class="td-chart-hit" cx="465" cy="301" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="271.5" y="259" width="387" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="280.5" y="279">Collection view, one fixed height, 10000: 5.4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>Collection view, one fixed height, 100000: 6.2</title>
<circle class="td-chart-hit" cx="619" cy="300.85" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="320.8" y="258.85" width="395.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="329.8" y="278.85">Collection view, one fixed height, 100000: 6.2</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-2" tabindex="0"><title>SwiftUI List, 100: 3</title>
<circle class="td-chart-hit" cx="157" cy="301.44" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="66" y="259.44" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="75" y="279.44">SwiftUI List, 100: 3</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-2" tabindex="0"><title>SwiftUI List, 1000: 3.5</title>
<circle class="td-chart-hit" cx="311" cy="301.35" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="207.7" y="259.35" width="206.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="216.7" y="279.35">SwiftUI List, 1000: 3.5</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-2" tabindex="0"><title>SwiftUI List, 10000: 4.8</title>
<circle class="td-chart-hit" cx="465" cy="301.11" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="357.6" y="259.11" width="214.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="366.6" y="279.11">SwiftUI List, 10000: 4.8</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-2" tabindex="0"><title>SwiftUI List, 100000: 17</title>
<circle class="td-chart-hit" cx="619" cy="298.85" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="501.2" y="256.85" width="214.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="510.2" y="276.85">SwiftUI List, 100000: 17</text>
</g>
</g>
</svg>
</div>
</figure>
<p><em>The self-sizing layout pays for the size of the list. A fixed height does not, and a List only a little.</em></p>
<p>On an iPad I counted how many cells the layout asked to size themselves at first display. It was 36, whether the list had 100 rows or 100,000, while the time went from 4.7 to 1,063 milliseconds. So the growing cost is not in asking cells. It is in the layout. Give the collection view one fixed row height and the same append takes 5 or 6 milliseconds from 1,000 rows up to 100,000. The container is faster than the <code>List</code> only when you make the decision SwiftUI makes for you.</p>
<p>That is the shape of the whole thing. A hand-built container wins when you remove work, with one row height and updates in place. The <code>List</code> wins when your rows must measure themselves, because its table or collection view only measures what is on screen. Neither is “faster”. They are two different feeds to the same kind of container, and the cost lives in the feed.</p>
<h2>The iPad did not agree with the Mac</h2>
<div class="td-callout">
<p class="td-callout-title">Read the iPad numbers as measurements, not as a curve</p>
<p class="td-callout-body">On a real iPad Pro, appending 50 rows to a list of 10,000 cost the `List` 74 milliseconds and the self-sizing collection view 14, which is the other way round from the Mac. Device runs wait for display frames, so some runs take a hundred milliseconds even for an operation that takes 0.2 when left alone. My first iPad numbers also did not reproduce after I fixed a leak in my own runner, and I do not know why. The mechanism, the container underneath, is the same. The timings are not the Mac&#39;s.</p>
</div>
<h2>How I got one of these wrong</h2>
<p>I should tell you about the table I got wrong, because it is the best reason to trust the rest. For a row that looks like a real forum post, with an avatar, an author line, one to twelve lines of text and a picture on one in four, the first version of my results said a <code>List</code> takes 3,031 milliseconds to show 100,000 of them, and I drew the opposite conclusion from the one I now hold.</p>
<p>The numbers were wrong because of my own harness. To draw a post I had put an <code>if</code> inside each row of the <code>List</code>, which made every row a conditional view, and the <code>List</code> several times slower. I only found it because a control I had promised in the protocol, rerunning older cells against the code from before the change, did not match for the <code>List</code>. I fixed the harness, measured every <code>List</code> cell again, and replaced them. With the corrected numbers, the <code>List</code> shows those 100,000 posts in 67 milliseconds.</p>
<p>The lesson is the one that sits under this whole post: when a number surprises you, suspect the instrument before the platform. It is the reason I read the classes two ways, and the reason I ran the probe on a plain table view first.</p>
<h2>What I have not shown</h2>
<div class="td-callout">
<p class="td-callout-title">Only List and Table were probed</p>
<p class="td-callout-body">What is under LazyVStack and LazyVGrid, I do not know.</p>
</div>
<ul><li><p><strong>Containers:</strong> I did not point the probe at <code>LazyVStack</code> or <code>LazyVGrid</code>.</p></li><li><p><strong>Machines:</strong> one Mac, an iPhone simulator, a real iPhone and a real iPad. The real devices took a slightly different route to the same container.</p></li><li><p><strong>Versions:</strong> macOS 27.2.1, iOS 27.0 on the simulator and iOS 27.2.1 on the devices. The class names are private and can change in any release, so I say nothing about other versions.</p></li><li><p><strong>Not looked at:</strong> other list styles, sections, hierarchical lists, selection, edit mode, and what the render server does.</p></li></ul>
<p>If the question is whether SwiftUI wraps the platform for everything it draws, I do not know yet. For lists and tables, I can show you the class names.</p>
<h2>So, what changes</h2>
<p>The things that go wrong with a <code>List</code> are the things that go wrong with a table view or a collection view, because that is what it is. If something is slow in a <code>List</code>, the answer is rarely “SwiftUI is slow”. It is closer to “what am I asking a table view or a collection view to do, and how is SwiftUI translating it?” And the choice on an iPhone is not between UIKit and SwiftUI as containers. Both sides are a <code>UICollectionView</code>. The choice is who feeds it, and how its rows get their height.</p>
<h2>Where the numbers come from</h2>
<p>Every number here comes from my measured runs, which I describe in a longer article, “Is a Collection View Faster Than a SwiftUI List? I Measured.”, coming next. The code that took them, the answer key and the raw data of every run are already in a public repository, <a href="https://codeberg.org/Mihaela/ListBench">ListBench</a>. You do not have to take my word for any of it:</p>
<figure class="td-term"><div class="td-term-bar"><span class="td-term-dots" aria-hidden="true"></span><span class="td-term-title">Run it yourself</span></div><pre class="td-term-body"><code><span class="td-term-prompt">$</span> <span class="td-term-cmd">git clone https://codeberg.org/Mihaela/ListBench.git</span>
<span class="td-term-prompt">$</span> <span class="td-term-cmd">cd ListBench</span>
<span class="td-term-prompt">$</span> <span class="td-term-cmd">swift run -c release ListBenchRun --out data.json --isolate --max-load 10</span></code></pre></figure>

<p><em>Same code, same answer key, your machine.</em></p>]]></content:encoded>
</item>
<item>
<title>How SwiftUI Animates, and Where It Is Not Like UIKit</title>
<link>https://aleahim.com/blog/how-swiftui-animates/</link>
<guid isPermaLink="true">https://aleahim.com/blog/how-swiftui-animates/</guid>
<pubDate>Mon, 09 Nov 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>UIKit and AppKit hand the render server a description of a motion and walk away. SwiftUI does not, and it does not behave the same on a Mac as on an iPhone. I measured both on a Mac, two simulators, a real iPhone and a real iPad.</description>
<content:encoded><![CDATA[<h1>How SwiftUI Animates, and Where It Is Not Like UIKit</h1>
<p><em>Correction, 25 November 2026. Three statements in an earlier version did not match the recorded results and are fixed: the custom animation callbacks during the blocked main thread are 26 on the simulators, 32 on the real iPhone and 52 on the real iPad, not 24, 34 and 48; the Mac’s setter calls for a case run from 54 to 180, not 184; and on iPhone and iPad one to four calls of a case to a custom animation’s <code>animate</code> are on the main thread, the rest off it.</em></p>
<p>Take one dot. Move it across a view in half a second. Do it with <code>UIView.animate</code>, then do it with <code>withAnimation</code>. On screen the two look the same. Underneath they are not the same thing, and the difference changes depending on whether you are on a Mac or on an iPhone.</p>
<p>I thought I knew the answer. I did not, and the first answer I was given turned out to be true on one platform and false on the other. So I stopped reading and started measuring. This post is the measurements: charts drawn from the recorded data, byte dumps of what was really in memory, and recordings of the real screens.</p>
<h2>The answers I started with</h2>
<p>Core Animation is data. You describe a motion once: a key path, a from value, a to value, a duration, a curve. That description goes to the render server, a separate process, and the render server runs it frame after frame. Your app does nothing more until the animation ends.</p>
<p>Then someone showed me a call stack from a Mac that said SwiftUI is the opposite. On each pass the system asks the app for the state at this time, the app works it out on the main thread and writes the layer. A pull model. The render server only sees the results.</p>
<p>And Apple says something else again. In WWDC 2023, session 10156, “Explore SwiftUI animation”, the sentence is that for built-in animatable attributes like <code>scaleEffect</code>, SwiftUI does the work off the main thread and without calling into your view code.</p>
<p>Those three cannot describe one mechanism. This is what I ended up with, drawn first so you can hold it against the evidence in the rest of the post:</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart LR
  subgraph A[&quot;UIKit and AppKit&quot;]
    direction TB
    a1[&quot;you animate&lt;br/&gt;a view&quot;] --&gt; a2[&quot;one animation&lt;br/&gt;object is added&lt;br/&gt;to the layer&quot;] --&gt; a3[&quot;one commit to&lt;br/&gt;the render server&quot;] --&gt; a4[&quot;the render server&lt;br/&gt;runs it,&lt;br/&gt;every frame&quot;]
  end
  subgraph B[&quot;SwiftUI on the Mac&quot;]
    direction TB
    b1[&quot;you call&lt;br/&gt;withAnimation&quot;] --&gt; b2[&quot;SwiftUI works out&lt;br/&gt;the value on the&lt;br/&gt;main thread,&lt;br/&gt;every pass&quot;] --&gt; b3[&quot;it writes&lt;br/&gt;the layer&quot;] --&gt; b4[&quot;the render server&lt;br/&gt;draws what&lt;br/&gt;it is given&quot;]
  end
  subgraph C[&quot;SwiftUI on iPhone and iPad&quot;]
    direction TB
    c1[&quot;you call&lt;br/&gt;withAnimation&quot;] --&gt; c2[&quot;SwiftUI works out&lt;br/&gt;the value on its&lt;br/&gt;own thread,&lt;br/&gt;every frame&quot;] --&gt; c3[&quot;the value goes&lt;br/&gt;into shared&lt;br/&gt;memory&quot;] --&gt; c4[&quot;a small commit&lt;br/&gt;says the memory&lt;br/&gt;changed&quot;] --&gt; c5[&quot;the render server&lt;br/&gt;draws what&lt;br/&gt;it is given&quot;]
  end
  A ~~~ B
  B ~~~ C
</pre>
</figure>
<h2>How I measured</h2>
<p>I built a small probe. A SwiftUI view, a stack of two colours, hosted in a window on screen. One property driven by a switch inside <code>withAnimation</code>: opacity, offset, width, scale or rotation. Four kinds of animation: linear, ease in and out, a spring, and a custom animation, which is a callback that returns a value. That is 20 cases. The same properties moved with the framework’s own call, <code>UIView.animate</code> on iPhone and iPad and <code>NSAnimationContext</code> on the Mac, as the baseline.</p>
<p>While the motion ran I recorded three things: every call to the layer’s setters and whether it came on the main thread, every call to <code>addAnimation:forKey:</code>, and the model value and the presentation value of every layer, sampled every 4 milliseconds.</p>
<p>If the app writes the model value on many passes and adds no animation, the app is running the motion. If an animation is added and the model value is written once, the render server is. If the model value is written once, no animation is added through the public call, and the presentation value moves anyway, something I cannot see is making the motion.</p>
<p>I ran it on a Mac (macOS 27.0.1), on an iPhone and an iPad simulator (27.0, 60 Hz), and on a real iPhone 17 Pro Max and a real iPad Pro (27.2, 120 Hz).</p>
<h2>What the layer received</h2>
<table><thead><tr><th>Platform</th><th>Verdict, 20 cases</th><th>Different model values per case</th><th>Values set on presentation modifiers per case</th></tr></thead><tbody><tr><td>Mac, macOS 27.0.1</td><td>20 appWrites</td><td>26 to 46</td><td>none</td></tr><tr><td>iPhone simulator, iOS 27.0</td><td>20 presentationModifier</td><td>2 to 3</td><td>40 to 172</td></tr><tr><td>iPad simulator, iPadOS 27.0</td><td>20 presentationModifier</td><td>2 to 3</td><td>42 to 167</td></tr><tr><td>iPhone 17 Pro Max, iOS 27.2</td><td>20 presentationModifier</td><td>2 to 3</td><td>42 to 171</td></tr><tr><td>iPad Pro M4, iPadOS 27.2</td><td>20 presentationModifier</td><td>2 to 3</td><td>90 to 341</td></tr></tbody></table>
<p>The table is the whole result of the 20 cases, per platform. On the Mac, SwiftUI wrote the layer’s model value on 26 to 46 different values in half a second, with between 54 and 180 setter calls for a case, every one of them on the main thread, and added no animation, ever. It did not matter whether the animation was linear, ease, spring or custom, or whether the property was opacity, offset, width, scale or rotation.</p>
<p>On iPhone and iPad the model value was written two or three times: the start and the end. No animation was added through <code>addAnimation:forKey:</code>. And the presentation value, what is actually drawn, took 22 to 80 different values as it moved. The motion is real, the app does not write it on every pass, and it is not a public animation object either.</p>
<p>The control is the framework’s own animation. On the Mac, the six cases AppKit could express each added exactly one animation, with the model written once and the presentation taking 32 to 33 values. On iPhone and iPad, 15 UIKit cases did the same, with 26 to 106 presentation values. The probe can see a handed-off animation when there is one.</p>
<h2>Block the main thread</h2>
<p>The question that matters for an app is simple. If the main thread is busy, does the animation keep moving?</p>
<p>I put a blue square on screen and blocked the main thread for half a second in the middle of the motion. While the square is lit, the thread is blocked. I recorded the screen and read every frame for where the red dot was. On the Mac and in the simulator I read the composited display with a private call. That call returns a blank surface on a real device, so for the devices I did what QuickTime does: plug the device in by USB, switch on one CoreMediaIO setting, and each device shows up as a capture device. The recording is 60 frames a second on both devices, also on the 120 Hz iPad. The Mac capture ran at about 14 frames a second, which is why its chart has fewer, larger steps.</p>
<p>In every chart below, the horizontal axis is seconds from the moment the blue marker lit, sampled every 0.15 seconds, and a * after a time means the main thread was blocked then. The vertical axis is where the dot was, as a fraction of its travel. For each time the chart shows the last frame the screen had drawn by then, which is what you would have seen.</p>
<h3>The Mac</h3>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">Mac: where the dot was while the main thread was blocked</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="Mac: where the dot was while the main thread was blocked"
>
<desc>line chart with 12 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="246.4"
  x2="696"
  y2="246.4"
></line>
<text
  class="td-chart-value"
  x="70"
  y="250.4"
  text-anchor="end"
>0.2</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="190.8"
  x2="696"
  y2="190.8"
></line>
<text
  class="td-chart-value"
  x="70"
  y="194.8"
  text-anchor="end"
>0.4</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="135.2"
  x2="696"
  y2="135.2"
></line>
<text
  class="td-chart-value"
  x="70"
  y="139.2"
  text-anchor="end"
>0.6</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="79.6"
  x2="696"
  y2="79.6"
></line>
<text
  class="td-chart-value"
  x="70"
  y="83.6"
  text-anchor="end"
>0.8</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>1</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<polyline class="td-chart-line td-chart-series-0" points="105.67,253.91 157,236.67 208.33,215.54 259.67,196.08 311,178.85 362.33,163.28 413.67,149.93 465,134.37 516.33,112.96 567.67,97.67 619,76.54 670.33,59.31"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="105.67"
  cy="253.91"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="157"
  cy="236.67"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="208.33"
  cy="215.54"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="259.67"
  cy="196.08"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="311"
  cy="178.85"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="362.33"
  cy="163.28"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="413.67"
  cy="149.93"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="465"
  cy="134.37"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="516.33"
  cy="112.96"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="567.67"
  cy="97.67"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="619"
  cy="76.54"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="670.33"
  cy="59.31"
  r="4"
></circle>
<polyline class="td-chart-line td-chart-series-1" points="105.67,244.18 157,224.72 208.33,205.53 259.67,188.3 311,182.46 362.33,182.46 413.67,182.46 465,118.8 516.33,105.18 567.67,85.72 619,68.2 670.33,52.91"></polyline>
<circle
  class="td-chart-point td-chart-series-1"
  cx="105.67"
  cy="244.18"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="157"
  cy="224.72"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="208.33"
  cy="205.53"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="259.67"
  cy="188.3"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="311"
  cy="182.46"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="362.33"
  cy="182.46"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="413.67"
  cy="182.46"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="465"
  cy="118.8"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="516.33"
  cy="105.18"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="567.67"
  cy="85.72"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="619"
  cy="68.2"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="670.33"
  cy="52.91"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="105.67"
  y="324"
  text-anchor="middle"
>-0.45</text>
<text
  class="td-chart-label"
  x="157"
  y="324"
  text-anchor="middle"
>-0.30</text>
<text
  class="td-chart-label"
  x="208.33"
  y="324"
  text-anchor="middle"
>-0.15</text>
<text
  class="td-chart-label"
  x="259.67"
  y="324"
  text-anchor="middle"
>0.00 *</text>
<text
  class="td-chart-label"
  x="311"
  y="324"
  text-anchor="middle"
>0.15 *</text>
<text
  class="td-chart-label"
  x="362.33"
  y="324"
  text-anchor="middle"
>0.30 *</text>
<text
  class="td-chart-label"
  x="413.67"
  y="324"
  text-anchor="middle"
>0.45 *</text>
<text
  class="td-chart-label"
  x="465"
  y="324"
  text-anchor="middle"
>0.60</text>
<text
  class="td-chart-label"
  x="516.33"
  y="324"
  text-anchor="middle"
>0.75</text>
<text
  class="td-chart-label"
  x="567.67"
  y="324"
  text-anchor="middle"
>0.90</text>
<text
  class="td-chart-label"
  x="619"
  y="324"
  text-anchor="middle"
>1.05</text>
<text
  class="td-chart-label"
  x="670.33"
  y="324"
  text-anchor="middle"
>1.20</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>seconds from the marker, * the main thread was blocked</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>the dot&#39;s place, as a fraction of its travel</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>AppKit</text>
<rect
  class="td-chart-series-1"
  x="165.6"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="183.6"
  y="346"
  text-anchor="start"
>SwiftUI</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, -0.45: 0.17</title>
<circle class="td-chart-hit" cx="105.67" cy="253.91" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="18.77" y="211.91" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="27.77" y="231.91">AppKit, -0.45: 0.17</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, -0.30: 0.23</title>
<circle class="td-chart-hit" cx="157" cy="236.67" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="70.1" y="194.67" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="79.1" y="214.67">AppKit, -0.30: 0.23</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, -0.15: 0.31</title>
<circle class="td-chart-hit" cx="208.33" cy="215.54" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="121.43" y="173.54" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="130.43" y="193.54">AppKit, -0.15: 0.31</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, 0.00 *: 0.38</title>
<circle class="td-chart-hit" cx="259.67" cy="196.08" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="168.67" y="154.08" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="177.67" y="174.08">AppKit, 0.00 *: 0.38</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, 0.15 *: 0.44</title>
<circle class="td-chart-hit" cx="311" cy="178.85" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="220" y="136.85" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="229" y="156.85">AppKit, 0.15 *: 0.44</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, 0.30 *: 0.5</title>
<circle class="td-chart-hit" cx="362.33" cy="163.28" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="275.43" y="121.28" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="284.43" y="141.28">AppKit, 0.30 *: 0.5</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, 0.45 *: 0.55</title>
<circle class="td-chart-hit" cx="413.67" cy="149.93" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="322.67" y="107.93" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="331.67" y="127.93">AppKit, 0.45 *: 0.55</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, 0.60: 0.6</title>
<circle class="td-chart-hit" cx="465" cy="134.37" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="386.3" y="92.37" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="395.3" y="112.37">AppKit, 0.60: 0.6</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, 0.75: 0.68</title>
<circle class="td-chart-hit" cx="516.33" cy="112.96" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="433.53" y="70.96" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="442.53" y="90.96">AppKit, 0.75: 0.68</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, 0.90: 0.73</title>
<circle class="td-chart-hit" cx="567.67" cy="97.67" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="484.87" y="55.67" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="493.87" y="75.67">AppKit, 0.90: 0.73</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, 1.05: 0.81</title>
<circle class="td-chart-hit" cx="619" cy="76.54" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="536.2" y="34.54" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="545.2" y="54.54">AppKit, 1.05: 0.81</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>AppKit, 1.20: 0.87</title>
<circle class="td-chart-hit" cx="670.33" cy="59.31" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="550.4" y="17.31" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="559.4" y="37.31">AppKit, 1.20: 0.87</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.45: 0.21</title>
<circle class="td-chart-hit" cx="105.67" cy="244.18" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="14.67" y="202.18" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="23.67" y="222.18">SwiftUI, -0.45: 0.21</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.30: 0.28</title>
<circle class="td-chart-hit" cx="157" cy="224.72" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="66" y="182.72" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="75" y="202.72">SwiftUI, -0.30: 0.28</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.15: 0.35</title>
<circle class="td-chart-hit" cx="208.33" cy="205.53" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="117.33" y="163.53" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="126.33" y="183.53">SwiftUI, -0.15: 0.35</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.00 *: 0.41</title>
<circle class="td-chart-hit" cx="259.67" cy="188.3" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="164.57" y="146.3" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="173.57" y="166.3">SwiftUI, 0.00 *: 0.41</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.15 *: 0.43</title>
<circle class="td-chart-hit" cx="311" cy="182.46" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="215.9" y="140.46" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="224.9" y="160.46">SwiftUI, 0.15 *: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.30 *: 0.43</title>
<circle class="td-chart-hit" cx="362.33" cy="182.46" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="267.23" y="140.46" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="276.23" y="160.46">SwiftUI, 0.30 *: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.45 *: 0.43</title>
<circle class="td-chart-hit" cx="413.67" cy="182.46" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="318.57" y="140.46" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="327.57" y="160.46">SwiftUI, 0.45 *: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.60: 0.66</title>
<circle class="td-chart-hit" cx="465" cy="118.8" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="378.1" y="76.8" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="387.1" y="96.8">SwiftUI, 0.60: 0.66</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.75: 0.71</title>
<circle class="td-chart-hit" cx="516.33" cy="105.18" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="429.43" y="63.18" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="438.43" y="83.18">SwiftUI, 0.75: 0.71</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.90: 0.78</title>
<circle class="td-chart-hit" cx="567.67" cy="85.72" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="480.77" y="43.72" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="489.77" y="63.72">SwiftUI, 0.90: 0.78</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 1.05: 0.84</title>
<circle class="td-chart-hit" cx="619" cy="68.2" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="532.1" y="26.2" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="541.1" y="46.2">SwiftUI, 1.05: 0.84</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 1.20: 0.9</title>
<circle class="td-chart-hit" cx="670.33" cy="52.91" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="550.4" y="10.91" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="559.4" y="30.91">SwiftUI, 1.20: 0.9</text>
</g>
</g>
</svg>
</div>
</figure>
<p>Blue is AppKit, green is SwiftUI. The AppKit dot keeps climbing through the block. The SwiftUI dot is flat for the whole stretch, then jumps to where it should have been. In the block shown, it stayed in one place for about half a second. Over the two blocks the probe judged, the longest wait was 586 milliseconds, and in the frames of the block that were not at its edges the SwiftUI dot was in a new place in none.</p>
<h3>The iPhone simulator</h3>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">iPhone simulator: where the dot was while the main thread was blocked</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="iPhone simulator: where the dot was while the main thread was blocked"
>
<desc>line chart with 12 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="246.4"
  x2="696"
  y2="246.4"
></line>
<text
  class="td-chart-value"
  x="70"
  y="250.4"
  text-anchor="end"
>0.2</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="190.8"
  x2="696"
  y2="190.8"
></line>
<text
  class="td-chart-value"
  x="70"
  y="194.8"
  text-anchor="end"
>0.4</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="135.2"
  x2="696"
  y2="135.2"
></line>
<text
  class="td-chart-value"
  x="70"
  y="139.2"
  text-anchor="end"
>0.6</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="79.6"
  x2="696"
  y2="79.6"
></line>
<text
  class="td-chart-value"
  x="70"
  y="83.6"
  text-anchor="end"
>0.8</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>1</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<polyline class="td-chart-line td-chart-series-0" points="105.67,246.4 157,229.16 208.33,211.93 259.67,192.75 311,175.51 362.33,158.55 413.67,141.04 465,123.8 516.33,106.57 567.67,89.05 619,71.82 670.33,54.3"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="105.67"
  cy="246.4"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="157"
  cy="229.16"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="208.33"
  cy="211.93"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="259.67"
  cy="192.75"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="311"
  cy="175.51"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="362.33"
  cy="158.55"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="413.67"
  cy="141.04"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="465"
  cy="123.8"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="516.33"
  cy="106.57"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="567.67"
  cy="89.05"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="619"
  cy="71.82"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="670.33"
  cy="54.3"
  r="4"
></circle>
<polyline class="td-chart-line td-chart-series-1" points="105.67,247.79 157,230.55 208.33,213.04 259.67,195.8 311,180.24 362.33,163 413.67,145.76 465,128.25 516.33,110.74 567.67,93.5 619,74.04 670.33,56.8"></polyline>
<circle
  class="td-chart-point td-chart-series-1"
  cx="105.67"
  cy="247.79"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="157"
  cy="230.55"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="208.33"
  cy="213.04"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="259.67"
  cy="195.8"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="311"
  cy="180.24"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="362.33"
  cy="163"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="413.67"
  cy="145.76"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="465"
  cy="128.25"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="516.33"
  cy="110.74"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="567.67"
  cy="93.5"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="619"
  cy="74.04"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="670.33"
  cy="56.8"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="105.67"
  y="324"
  text-anchor="middle"
>-0.45</text>
<text
  class="td-chart-label"
  x="157"
  y="324"
  text-anchor="middle"
>-0.30</text>
<text
  class="td-chart-label"
  x="208.33"
  y="324"
  text-anchor="middle"
>-0.15</text>
<text
  class="td-chart-label"
  x="259.67"
  y="324"
  text-anchor="middle"
>0.00 *</text>
<text
  class="td-chart-label"
  x="311"
  y="324"
  text-anchor="middle"
>0.15 *</text>
<text
  class="td-chart-label"
  x="362.33"
  y="324"
  text-anchor="middle"
>0.30 *</text>
<text
  class="td-chart-label"
  x="413.67"
  y="324"
  text-anchor="middle"
>0.45 *</text>
<text
  class="td-chart-label"
  x="465"
  y="324"
  text-anchor="middle"
>0.60</text>
<text
  class="td-chart-label"
  x="516.33"
  y="324"
  text-anchor="middle"
>0.75</text>
<text
  class="td-chart-label"
  x="567.67"
  y="324"
  text-anchor="middle"
>0.90</text>
<text
  class="td-chart-label"
  x="619"
  y="324"
  text-anchor="middle"
>1.05</text>
<text
  class="td-chart-label"
  x="670.33"
  y="324"
  text-anchor="middle"
>1.20</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>seconds from the marker, * the main thread was blocked</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>the dot&#39;s place, as a fraction of its travel</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>UIKit</text>
<rect
  class="td-chart-series-1"
  x="153.12"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="171.12"
  y="346"
  text-anchor="start"
>SwiftUI</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.45: 0.2</title>
<circle class="td-chart-hit" cx="105.67" cy="246.4" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="26.97" y="204.4" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="35.97" y="224.4">UIKit, -0.45: 0.2</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.30: 0.26</title>
<circle class="td-chart-hit" cx="157" cy="229.16" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="74.2" y="187.16" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="83.2" y="207.16">UIKit, -0.30: 0.26</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.15: 0.32</title>
<circle class="td-chart-hit" cx="208.33" cy="211.93" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="125.53" y="169.93" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="134.53" y="189.93">UIKit, -0.15: 0.32</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.00 *: 0.39</title>
<circle class="td-chart-hit" cx="259.67" cy="192.75" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="172.77" y="150.75" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="181.77" y="170.75">UIKit, 0.00 *: 0.39</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.15 *: 0.46</title>
<circle class="td-chart-hit" cx="311" cy="175.51" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="224.1" y="133.51" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="233.1" y="153.51">UIKit, 0.15 *: 0.46</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.30 *: 0.52</title>
<circle class="td-chart-hit" cx="362.33" cy="158.55" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="275.43" y="116.55" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="284.43" y="136.55">UIKit, 0.30 *: 0.52</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.45 *: 0.58</title>
<circle class="td-chart-hit" cx="413.67" cy="141.04" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="326.77" y="99.04" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="335.77" y="119.04">UIKit, 0.45 *: 0.58</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.60: 0.64</title>
<circle class="td-chart-hit" cx="465" cy="123.8" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="386.3" y="81.8" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="395.3" y="101.8">UIKit, 0.60: 0.64</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.75: 0.7</title>
<circle class="td-chart-hit" cx="516.33" cy="106.57" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="441.73" y="64.57" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="450.73" y="84.57">UIKit, 0.75: 0.7</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.90: 0.77</title>
<circle class="td-chart-hit" cx="567.67" cy="89.05" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="488.97" y="47.05" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="497.97" y="67.05">UIKit, 0.90: 0.77</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 1.05: 0.83</title>
<circle class="td-chart-hit" cx="619" cy="71.82" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="540.3" y="29.82" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="549.3" y="49.82">UIKit, 1.05: 0.83</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 1.20: 0.89</title>
<circle class="td-chart-hit" cx="670.33" cy="54.3" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="558.6" y="12.3" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="567.6" y="32.3">UIKit, 1.20: 0.89</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.45: 0.2</title>
<circle class="td-chart-hit" cx="105.67" cy="247.79" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="18.77" y="205.79" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="27.77" y="225.79">SwiftUI, -0.45: 0.2</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.30: 0.26</title>
<circle class="td-chart-hit" cx="157" cy="230.55" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="66" y="188.55" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="75" y="208.55">SwiftUI, -0.30: 0.26</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.15: 0.32</title>
<circle class="td-chart-hit" cx="208.33" cy="213.04" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="117.33" y="171.04" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="126.33" y="191.04">SwiftUI, -0.15: 0.32</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.00 *: 0.38</title>
<circle class="td-chart-hit" cx="259.67" cy="195.8" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="164.57" y="153.8" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="173.57" y="173.8">SwiftUI, 0.00 *: 0.38</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.15 *: 0.44</title>
<circle class="td-chart-hit" cx="311" cy="180.24" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="215.9" y="138.24" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="224.9" y="158.24">SwiftUI, 0.15 *: 0.44</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.30 *: 0.5</title>
<circle class="td-chart-hit" cx="362.33" cy="163" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="271.33" y="121" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="280.33" y="141">SwiftUI, 0.30 *: 0.5</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.45 *: 0.56</title>
<circle class="td-chart-hit" cx="413.67" cy="145.76" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="318.57" y="103.76" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="327.57" y="123.76">SwiftUI, 0.45 *: 0.56</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.60: 0.62</title>
<circle class="td-chart-hit" cx="465" cy="128.25" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="378.1" y="86.25" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="387.1" y="106.25">SwiftUI, 0.60: 0.62</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.75: 0.69</title>
<circle class="td-chart-hit" cx="516.33" cy="110.74" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="429.43" y="68.74" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="438.43" y="88.74">SwiftUI, 0.75: 0.69</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.90: 0.75</title>
<circle class="td-chart-hit" cx="567.67" cy="93.5" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="480.77" y="51.5" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="489.77" y="71.5">SwiftUI, 0.90: 0.75</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 1.05: 0.82</title>
<circle class="td-chart-hit" cx="619" cy="74.04" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="532.1" y="32.04" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="541.1" y="52.04">SwiftUI, 1.05: 0.82</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 1.20: 0.88</title>
<circle class="td-chart-hit" cx="670.33" cy="56.8" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="542.2" y="14.8" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="551.2" y="34.8">SwiftUI, 1.20: 0.88</text>
</g>
</g>
</svg>
</div>
</figure>
<h3>A real iPad Pro</h3>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">iPad Pro, a real device: where the dot was while the main thread was blocked</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="iPad Pro, a real device: where the dot was while the main thread was blocked"
>
<desc>line chart with 12 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="246.4"
  x2="696"
  y2="246.4"
></line>
<text
  class="td-chart-value"
  x="70"
  y="250.4"
  text-anchor="end"
>0.2</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="190.8"
  x2="696"
  y2="190.8"
></line>
<text
  class="td-chart-value"
  x="70"
  y="194.8"
  text-anchor="end"
>0.4</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="135.2"
  x2="696"
  y2="135.2"
></line>
<text
  class="td-chart-value"
  x="70"
  y="139.2"
  text-anchor="end"
>0.6</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="79.6"
  x2="696"
  y2="79.6"
></line>
<text
  class="td-chart-value"
  x="70"
  y="83.6"
  text-anchor="end"
>0.8</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>1</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<polyline class="td-chart-line td-chart-series-0" points="105.67,240.84 157,223.05 208.33,205.81 259.67,188.58 311,173.29 362.33,155.49 413.67,138.26 465,121.02 516.33,103.79 567.67,85.99 619,70.7 670.33,51.52"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="105.67"
  cy="240.84"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="157"
  cy="223.05"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="208.33"
  cy="205.81"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="259.67"
  cy="188.58"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="311"
  cy="173.29"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="362.33"
  cy="155.49"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="413.67"
  cy="138.26"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="465"
  cy="121.02"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="516.33"
  cy="103.79"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="567.67"
  cy="85.99"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="619"
  cy="70.7"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="670.33"
  cy="51.52"
  r="4"
></circle>
<polyline class="td-chart-line td-chart-series-1" points="105.67,252.52 157,233.33 208.33,216.1 259.67,198.86 311,181.35 362.33,165.78 413.67,148.54 465,131.03 516.33,113.52 567.67,96.28 619,77.1 670.33,59.86"></polyline>
<circle
  class="td-chart-point td-chart-series-1"
  cx="105.67"
  cy="252.52"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="157"
  cy="233.33"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="208.33"
  cy="216.1"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="259.67"
  cy="198.86"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="311"
  cy="181.35"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="362.33"
  cy="165.78"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="413.67"
  cy="148.54"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="465"
  cy="131.03"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="516.33"
  cy="113.52"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="567.67"
  cy="96.28"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="619"
  cy="77.1"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="670.33"
  cy="59.86"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="105.67"
  y="324"
  text-anchor="middle"
>-0.45</text>
<text
  class="td-chart-label"
  x="157"
  y="324"
  text-anchor="middle"
>-0.30</text>
<text
  class="td-chart-label"
  x="208.33"
  y="324"
  text-anchor="middle"
>-0.15</text>
<text
  class="td-chart-label"
  x="259.67"
  y="324"
  text-anchor="middle"
>0.00 *</text>
<text
  class="td-chart-label"
  x="311"
  y="324"
  text-anchor="middle"
>0.15 *</text>
<text
  class="td-chart-label"
  x="362.33"
  y="324"
  text-anchor="middle"
>0.30 *</text>
<text
  class="td-chart-label"
  x="413.67"
  y="324"
  text-anchor="middle"
>0.45 *</text>
<text
  class="td-chart-label"
  x="465"
  y="324"
  text-anchor="middle"
>0.60</text>
<text
  class="td-chart-label"
  x="516.33"
  y="324"
  text-anchor="middle"
>0.75</text>
<text
  class="td-chart-label"
  x="567.67"
  y="324"
  text-anchor="middle"
>0.90</text>
<text
  class="td-chart-label"
  x="619"
  y="324"
  text-anchor="middle"
>1.05</text>
<text
  class="td-chart-label"
  x="670.33"
  y="324"
  text-anchor="middle"
>1.20</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>seconds from the marker, * the main thread was blocked</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>the dot&#39;s place, as a fraction of its travel</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>UIKit</text>
<rect
  class="td-chart-series-1"
  x="153.12"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="171.12"
  y="346"
  text-anchor="start"
>SwiftUI</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.45: 0.22</title>
<circle class="td-chart-hit" cx="105.67" cy="240.84" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="22.87" y="198.84" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="31.87" y="218.84">UIKit, -0.45: 0.22</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.30: 0.28</title>
<circle class="td-chart-hit" cx="157" cy="223.05" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="74.2" y="181.05" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="83.2" y="201.05">UIKit, -0.30: 0.28</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.15: 0.35</title>
<circle class="td-chart-hit" cx="208.33" cy="205.81" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="125.53" y="163.81" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="134.53" y="183.81">UIKit, -0.15: 0.35</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.00 *: 0.41</title>
<circle class="td-chart-hit" cx="259.67" cy="188.58" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="172.77" y="146.58" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="181.77" y="166.58">UIKit, 0.00 *: 0.41</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.15 *: 0.46</title>
<circle class="td-chart-hit" cx="311" cy="173.29" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="224.1" y="131.29" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="233.1" y="151.29">UIKit, 0.15 *: 0.46</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.30 *: 0.53</title>
<circle class="td-chart-hit" cx="362.33" cy="155.49" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="275.43" y="113.49" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="284.43" y="133.49">UIKit, 0.30 *: 0.53</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.45 *: 0.59</title>
<circle class="td-chart-hit" cx="413.67" cy="138.26" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="326.77" y="96.26" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="335.77" y="116.26">UIKit, 0.45 *: 0.59</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.60: 0.65</title>
<circle class="td-chart-hit" cx="465" cy="121.02" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="386.3" y="79.02" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="395.3" y="99.02">UIKit, 0.60: 0.65</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.75: 0.71</title>
<circle class="td-chart-hit" cx="516.33" cy="103.79" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="437.63" y="61.79" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="446.63" y="81.79">UIKit, 0.75: 0.71</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.90: 0.78</title>
<circle class="td-chart-hit" cx="567.67" cy="85.99" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="488.97" y="43.99" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="497.97" y="63.99">UIKit, 0.90: 0.78</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 1.05: 0.83</title>
<circle class="td-chart-hit" cx="619" cy="70.7" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="540.3" y="28.7" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="549.3" y="48.7">UIKit, 1.05: 0.83</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 1.20: 0.9</title>
<circle class="td-chart-hit" cx="670.33" cy="51.52" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="566.8" y="9.52" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="575.8" y="29.52">UIKit, 1.20: 0.9</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.45: 0.18</title>
<circle class="td-chart-hit" cx="105.67" cy="252.52" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="14.67" y="210.52" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="23.67" y="230.52">SwiftUI, -0.45: 0.18</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.30: 0.25</title>
<circle class="td-chart-hit" cx="157" cy="233.33" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="66" y="191.33" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="75" y="211.33">SwiftUI, -0.30: 0.25</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.15: 0.31</title>
<circle class="td-chart-hit" cx="208.33" cy="216.1" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="117.33" y="174.1" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="126.33" y="194.1">SwiftUI, -0.15: 0.31</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.00 *: 0.37</title>
<circle class="td-chart-hit" cx="259.67" cy="198.86" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="164.57" y="156.86" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="173.57" y="176.86">SwiftUI, 0.00 *: 0.37</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.15 *: 0.43</title>
<circle class="td-chart-hit" cx="311" cy="181.35" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="215.9" y="139.35" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="224.9" y="159.35">SwiftUI, 0.15 *: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.30 *: 0.49</title>
<circle class="td-chart-hit" cx="362.33" cy="165.78" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="267.23" y="123.78" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="276.23" y="143.78">SwiftUI, 0.30 *: 0.49</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.45 *: 0.55</title>
<circle class="td-chart-hit" cx="413.67" cy="148.54" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="318.57" y="106.54" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="327.57" y="126.54">SwiftUI, 0.45 *: 0.55</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.60: 0.61</title>
<circle class="td-chart-hit" cx="465" cy="131.03" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="378.1" y="89.03" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="387.1" y="109.03">SwiftUI, 0.60: 0.61</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.75: 0.68</title>
<circle class="td-chart-hit" cx="516.33" cy="113.52" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="429.43" y="71.52" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="438.43" y="91.52">SwiftUI, 0.75: 0.68</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.90: 0.74</title>
<circle class="td-chart-hit" cx="567.67" cy="96.28" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="480.77" y="54.28" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="489.77" y="74.28">SwiftUI, 0.90: 0.74</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 1.05: 0.81</title>
<circle class="td-chart-hit" cx="619" cy="77.1" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="532.1" y="35.1" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="541.1" y="55.1">SwiftUI, 1.05: 0.81</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 1.20: 0.87</title>
<circle class="td-chart-hit" cx="670.33" cy="59.86" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="542.2" y="17.86" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="551.2" y="37.86">SwiftUI, 1.20: 0.87</text>
</g>
</g>
</svg>
</div>
</figure>
<h3>A real iPhone 17 Pro Max</h3>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">iPhone 17 Pro Max, a real device: where the dot was while the main thread was blocked</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="iPhone 17 Pro Max, a real device: where the dot was while the main thread was blocked"
>
<desc>line chart with 12 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="246.4"
  x2="696"
  y2="246.4"
></line>
<text
  class="td-chart-value"
  x="70"
  y="250.4"
  text-anchor="end"
>0.2</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="190.8"
  x2="696"
  y2="190.8"
></line>
<text
  class="td-chart-value"
  x="70"
  y="194.8"
  text-anchor="end"
>0.4</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="135.2"
  x2="696"
  y2="135.2"
></line>
<text
  class="td-chart-value"
  x="70"
  y="139.2"
  text-anchor="end"
>0.6</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="79.6"
  x2="696"
  y2="79.6"
></line>
<text
  class="td-chart-value"
  x="70"
  y="83.6"
  text-anchor="end"
>0.8</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>1</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<polyline class="td-chart-line td-chart-series-0" points="105.67,248.07 157,230.55 208.33,212.76 259.67,196.08 311,180.24 362.33,163.56 413.67,145.76 465,128.25 516.33,110.46 567.67,93.78 619,75.99 670.33,58.47"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="105.67"
  cy="248.07"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="157"
  cy="230.55"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="208.33"
  cy="212.76"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="259.67"
  cy="196.08"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="311"
  cy="180.24"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="362.33"
  cy="163.56"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="413.67"
  cy="145.76"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="465"
  cy="128.25"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="516.33"
  cy="110.46"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="567.67"
  cy="93.78"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="619"
  cy="75.99"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="670.33"
  cy="58.47"
  r="4"
></circle>
<polyline class="td-chart-line td-chart-series-1" points="105.67,247.79 157,228.33 208.33,212.76 259.67,193.58 311,178.57 362.33,160.78 413.67,143.54 465,126.3 516.33,110.46 567.67,91 619,75.99 670.33,56.53"></polyline>
<circle
  class="td-chart-point td-chart-series-1"
  cx="105.67"
  cy="247.79"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="157"
  cy="228.33"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="208.33"
  cy="212.76"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="259.67"
  cy="193.58"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="311"
  cy="178.57"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="362.33"
  cy="160.78"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="413.67"
  cy="143.54"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="465"
  cy="126.3"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="516.33"
  cy="110.46"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="567.67"
  cy="91"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="619"
  cy="75.99"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="670.33"
  cy="56.53"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="105.67"
  y="324"
  text-anchor="middle"
>-0.45</text>
<text
  class="td-chart-label"
  x="157"
  y="324"
  text-anchor="middle"
>-0.30</text>
<text
  class="td-chart-label"
  x="208.33"
  y="324"
  text-anchor="middle"
>-0.15</text>
<text
  class="td-chart-label"
  x="259.67"
  y="324"
  text-anchor="middle"
>0.00 *</text>
<text
  class="td-chart-label"
  x="311"
  y="324"
  text-anchor="middle"
>0.15 *</text>
<text
  class="td-chart-label"
  x="362.33"
  y="324"
  text-anchor="middle"
>0.30 *</text>
<text
  class="td-chart-label"
  x="413.67"
  y="324"
  text-anchor="middle"
>0.45 *</text>
<text
  class="td-chart-label"
  x="465"
  y="324"
  text-anchor="middle"
>0.60</text>
<text
  class="td-chart-label"
  x="516.33"
  y="324"
  text-anchor="middle"
>0.75</text>
<text
  class="td-chart-label"
  x="567.67"
  y="324"
  text-anchor="middle"
>0.90</text>
<text
  class="td-chart-label"
  x="619"
  y="324"
  text-anchor="middle"
>1.05</text>
<text
  class="td-chart-label"
  x="670.33"
  y="324"
  text-anchor="middle"
>1.20</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>seconds from the marker, * the main thread was blocked</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>the dot&#39;s place, as a fraction of its travel</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>UIKit</text>
<rect
  class="td-chart-series-1"
  x="153.12"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="171.12"
  y="346"
  text-anchor="start"
>SwiftUI</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.45: 0.19</title>
<circle class="td-chart-hit" cx="105.67" cy="248.07" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="22.87" y="206.07" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="31.87" y="226.07">UIKit, -0.45: 0.19</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.30: 0.26</title>
<circle class="td-chart-hit" cx="157" cy="230.55" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="74.2" y="188.55" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="83.2" y="208.55">UIKit, -0.30: 0.26</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.15: 0.32</title>
<circle class="td-chart-hit" cx="208.33" cy="212.76" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="125.53" y="170.76" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="134.53" y="190.76">UIKit, -0.15: 0.32</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.00 *: 0.38</title>
<circle class="td-chart-hit" cx="259.67" cy="196.08" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="172.77" y="154.08" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="181.77" y="174.08">UIKit, 0.00 *: 0.38</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.15 *: 0.44</title>
<circle class="td-chart-hit" cx="311" cy="180.24" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="224.1" y="138.24" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="233.1" y="158.24">UIKit, 0.15 *: 0.44</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.30 *: 0.5</title>
<circle class="td-chart-hit" cx="362.33" cy="163.56" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="279.53" y="121.56" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="288.53" y="141.56">UIKit, 0.30 *: 0.5</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.45 *: 0.56</title>
<circle class="td-chart-hit" cx="413.67" cy="145.76" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="326.77" y="103.76" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="335.77" y="123.76">UIKit, 0.45 *: 0.56</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.60: 0.62</title>
<circle class="td-chart-hit" cx="465" cy="128.25" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="386.3" y="86.25" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="395.3" y="106.25">UIKit, 0.60: 0.62</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.75: 0.69</title>
<circle class="td-chart-hit" cx="516.33" cy="110.46" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="437.63" y="68.46" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="446.63" y="88.46">UIKit, 0.75: 0.69</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.90: 0.75</title>
<circle class="td-chart-hit" cx="567.67" cy="93.78" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="488.97" y="51.78" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="497.97" y="71.78">UIKit, 0.90: 0.75</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 1.05: 0.81</title>
<circle class="td-chart-hit" cx="619" cy="75.99" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="540.3" y="33.99" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="549.3" y="53.99">UIKit, 1.05: 0.81</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 1.20: 0.88</title>
<circle class="td-chart-hit" cx="670.33" cy="58.47" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="558.6" y="16.47" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="567.6" y="36.47">UIKit, 1.20: 0.88</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.45: 0.2</title>
<circle class="td-chart-hit" cx="105.67" cy="247.79" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="18.77" y="205.79" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="27.77" y="225.79">SwiftUI, -0.45: 0.2</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.30: 0.27</title>
<circle class="td-chart-hit" cx="157" cy="228.33" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="66" y="186.33" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="75" y="206.33">SwiftUI, -0.30: 0.27</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.15: 0.32</title>
<circle class="td-chart-hit" cx="208.33" cy="212.76" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="117.33" y="170.76" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="126.33" y="190.76">SwiftUI, -0.15: 0.32</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.00 *: 0.39</title>
<circle class="td-chart-hit" cx="259.67" cy="193.58" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="164.57" y="151.58" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="173.57" y="171.58">SwiftUI, 0.00 *: 0.39</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.15 *: 0.44</title>
<circle class="td-chart-hit" cx="311" cy="178.57" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="215.9" y="136.57" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="224.9" y="156.57">SwiftUI, 0.15 *: 0.44</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.30 *: 0.51</title>
<circle class="td-chart-hit" cx="362.33" cy="160.78" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="267.23" y="118.78" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="276.23" y="138.78">SwiftUI, 0.30 *: 0.51</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.45 *: 0.57</title>
<circle class="td-chart-hit" cx="413.67" cy="143.54" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="318.57" y="101.54" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="327.57" y="121.54">SwiftUI, 0.45 *: 0.57</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.60: 0.63</title>
<circle class="td-chart-hit" cx="465" cy="126.3" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="378.1" y="84.3" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="387.1" y="104.3">SwiftUI, 0.60: 0.63</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.75: 0.69</title>
<circle class="td-chart-hit" cx="516.33" cy="110.46" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="429.43" y="68.46" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="438.43" y="88.46">SwiftUI, 0.75: 0.69</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.90: 0.76</title>
<circle class="td-chart-hit" cx="567.67" cy="91" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="480.77" y="49" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="489.77" y="69">SwiftUI, 0.90: 0.76</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 1.05: 0.81</title>
<circle class="td-chart-hit" cx="619" cy="75.99" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="532.1" y="33.99" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="541.1" y="53.99">SwiftUI, 1.05: 0.81</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 1.20: 0.88</title>
<circle class="td-chart-hit" cx="670.33" cy="56.53" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="542.2" y="14.53" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="551.2" y="34.53">SwiftUI, 1.20: 0.88</text>
</g>
</g>
</svg>
</div>
</figure>
<p>On the simulator and on both real devices the two lines lie on top of each other. The SwiftUI dot kept moving through the block, at the same speed as the UIKit dot: 817 pixels a second against 816 on the iPad, 262 against 262 on the iPhone. The longest wait for a new place was one or two captured frames.</p>
<h3>All of it in one chart</h3>
<figure class="td-chart td-chart-bar">
<figcaption class="td-chart-caption">The longest time the dot stayed in one place in any block</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="The longest time the dot stayed in one place in any block"
>
<desc>bar chart with 5 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="209.33"
  x2="696"
  y2="209.33"
></line>
<text
  class="td-chart-value"
  x="70"
  y="213.33"
  text-anchor="end"
>200</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="116.67"
  x2="696"
  y2="116.67"
></line>
<text
  class="td-chart-value"
  x="70"
  y="120.67"
  text-anchor="end"
>400</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>600</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<rect
  class="td-chart-bar td-chart-series-0"
  x="107.6"
  y="246.4"
  width="32"
  height="55.6"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="230.8"
  y="290.42"
  width="32"
  height="11.58"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="354"
  y="286.71"
  width="32"
  height="15.29"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="477.2"
  y="286.71"
  width="32"
  height="15.29"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="600.4"
  y="286.71"
  width="32"
  height="15.29"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="141.6"
  y="30.49"
  width="32"
  height="271.51"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="264.8"
  y="275.13"
  width="32"
  height="26.87"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="388"
  y="286.71"
  width="32"
  height="15.29"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="511.2"
  y="286.71"
  width="32"
  height="15.29"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="634.4"
  y="78.21"
  width="32"
  height="223.79"
  rx="4"
></rect>
<text
  class="td-chart-label"
  x="141.6"
  y="324"
  text-anchor="middle"
>Mac</text>
<text
  class="td-chart-label"
  x="264.8"
  y="324"
  text-anchor="middle"
>iPhone sim</text>
<text
  class="td-chart-label"
  x="388"
  y="324"
  text-anchor="middle"
>iPad Pro</text>
<text
  class="td-chart-label"
  x="511.2"
  y="324"
  text-anchor="middle"
>iPhone 17</text>
<text
  class="td-chart-label"
  x="634.4"
  y="324"
  text-anchor="middle"
>iPad control</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>recording</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>milliseconds</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>UIKit and AppKit</text>
<rect
  class="td-chart-series-1"
  x="239.36"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="257.36"
  y="346"
  text-anchor="start"
>SwiftUI</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit and AppKit, Mac: 120</title>
<rect class="td-chart-hit" x="107.6" y="246.4" width="32" height="55.6"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="8" y="208.4" width="231.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="17" y="228.4">UIKit and AppKit, Mac: 120</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit and AppKit, iPhone sim: 25</title>
<rect class="td-chart-hit" x="230.8" y="280.21" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="106.6" y="252.42" width="280.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="115.6" y="272.42">UIKit and AppKit, iPhone sim: 25</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit and AppKit, iPad Pro: 33</title>
<rect class="td-chart-hit" x="354" y="278.36" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="238" y="248.71" width="264" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="247" y="268.71">UIKit and AppKit, iPad Pro: 33</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit and AppKit, iPhone 17: 33</title>
<rect class="td-chart-hit" x="477.2" y="278.36" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="357.1" y="248.71" width="272.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="366.1" y="268.71">UIKit and AppKit, iPhone 17: 33</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit and AppKit, iPad control: 33</title>
<rect class="td-chart-hit" x="600.4" y="278.36" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="419.2" y="248.71" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="428.2" y="268.71">UIKit and AppKit, iPad control: 33</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, Mac: 586</title>
<rect class="td-chart-hit" x="141.6" y="30.49" width="32" height="271.51"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="78.9" y="310" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="87.9" y="330">SwiftUI, Mac: 586</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, iPhone sim: 58</title>
<rect class="td-chart-hit" x="264.8" y="272.56" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="177.5" y="237.13" width="206.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="186.5" y="257.13">SwiftUI, iPhone sim: 58</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, iPad Pro: 33</title>
<rect class="td-chart-hit" x="388" y="278.36" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="308.9" y="248.71" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="317.9" y="268.71">SwiftUI, iPad Pro: 33</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, iPhone 17: 33</title>
<rect class="td-chart-hit" x="511.2" y="278.36" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="428" y="248.71" width="198.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="437" y="268.71">SwiftUI, iPhone 17: 33</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, iPad control: 483</title>
<rect class="td-chart-hit" x="634.4" y="78.21" width="32" height="223.79"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="484.8" y="40.21" width="231.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="493.8" y="60.21">SwiftUI, iPad control: 483</text>
</g>
</g>
</svg>
</div>
</figure>
<p>The last group, the iPad control, is a test I will come back to below. First, the same recordings as moving pictures.</p>
<h2>The same recordings, replayed</h2>
<p>Each of these videos replays one recording at half speed. The dot is put where the camera saw it, frame by frame, nothing smoothed. The top row is the framework’s own animation, the bottom row is SwiftUI. The blue square is lit while the main thread is blocked. The red bar under a row grows while that dot stays where it is, and a full bar is 0.6 seconds.</p>
<p>The Mac. Watch the red bar under the SwiftUI row.</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 4 / 1;">
<div class="td-embed-frame">
<video class="td-embed-video" controls preload="none" title="The Mac recording, replayed at half speed">
<source src="https://aleahim.com/images/blog/how-swiftui-animates/replay-mac.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</figure>
<p>The real iPad Pro. Nothing to see: no bar grows under either row.</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 4 / 1;">
<div class="td-embed-frame">
<video class="td-embed-video" controls preload="none" title="The iPad Pro recording, replayed at half speed">
<source src="https://aleahim.com/images/blog/how-swiftui-animates/replay-ipad.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</figure>
<p>The real iPhone 17 Pro Max.</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 4 / 1;">
<div class="td-embed-frame">
<video class="td-embed-video" controls preload="none" title="The iPhone 17 Pro Max recording, replayed at half speed">
<source src="https://aleahim.com/images/blog/how-swiftui-animates/replay-iphone.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</figure>
<h2>The real screens</h2>
<p>This is a frame from the recording of the iPad, with the blue square lit and the SwiftUI dot still moving.</p>
<p><img src="https://aleahim.com/images/blog/how-swiftui-animates/ipad-still-blocked-swiftui.jpg" alt="A real iPad Pro screen, recorded over USB: the blue square is lit and the main thread is blocked, and the SwiftUI dot is moving"></p>
<p>And the full recordings, trimmed to the run. The iPad, SwiftUI with the main thread blocked:</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 1210 / 834;">
<div class="td-embed-frame">
<video class="td-embed-video" controls preload="none" title="A real iPad Pro, SwiftUI, main thread blocked">
<source src="https://aleahim.com/images/blog/how-swiftui-animates/ipad-blocked-swiftui.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</figure>
<p>The iPad, UIKit, the same block:</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 1210 / 834;">
<div class="td-embed-frame">
<video class="td-embed-video" controls preload="none" title="A real iPad Pro, UIKit, main thread blocked">
<source src="https://aleahim.com/images/blog/how-swiftui-animates/ipad-blocked-uikit.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</figure>
<p>The iPhone, SwiftUI, cropped to the band the dot travels in:</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 2 / 1;">
<div class="td-embed-frame">
<video class="td-embed-video" controls preload="none" title="A real iPhone 17 Pro Max, SwiftUI, main thread blocked">
<source src="https://aleahim.com/images/blog/how-swiftui-animates/iphone-blocked-swiftui.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</figure>
<p>The iPhone, UIKit:</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 2 / 1;">
<div class="td-embed-frame">
<video class="td-embed-video" controls preload="none" title="A real iPhone 17 Pro Max, UIKit, main thread blocked">
<source src="https://aleahim.com/images/blog/how-swiftui-animates/iphone-blocked-uikit.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</figure>
<p>So with the main thread blocked, SwiftUI on iPhone and iPad keeps animating. SwiftUI on the Mac does not. Something other than the main thread is doing the work on the phones. To find out what, I had to go lower than Objective-C.</p>
<h2>Below Objective-C: what SwiftUI does on iPhone and iPad</h2>
<p>I listed every method with “animation” in its name on the layer and animation classes, public and private, hooked the ones I could, and recorded the thread and call stack of each call. None of the animation methods was called. But the custom animation showed where the clock runs. On the Mac its callback runs on the main thread, every call. On iPhone and iPad all but one to four calls of a case are off the main thread, on a thread named <code>com.apple.SwiftUI.AsyncRenderer</code>, reached from a display link of SwiftUI’s own. During the half second of blocked main thread, the callbacks went on: 26 inside the block on the simulators, 32 on the real iPhone and 52 on the real iPad, none of them on the main thread. On the Mac there were none.</p>
<p>Sampling the process while it animated showed the structure. On iPhone and iPad SwiftUI runs its own display link on that thread. Each tick it updates the graph, renders the display list asynchronously, and writes the values into what its symbols call an async layer. None of this exists on the Mac.</p>
<p>To see how those values reach the screen I attached a debugger to the simulator. SwiftUI’s <code>AsyncLayer.setValue</code> does not touch a layer: it queues the value. A function called <code>commitAsyncValues</code> takes the queued values, and it contains two groups of Core Animation calls. One builds <code>CABasicAnimation</code> objects and adds them. The other uses a class I had not heard of, <code>CAPresentationModifier</code>. I put breakpoints on both while an opacity animated. <code>addAnimation</code> was never called. <code>addPresentationModifier:</code> was called 44 times and <code>-[CAPresentationModifier setValue:]</code> 302 times, all on the <code>AsyncRenderer</code> thread, with the values rising frame by frame.</p>
<p>A presentation modifier is a private Core Animation class, not in the public headers. A layer that has one for a key path shows that value in its presentation without a change to the model value and without an animation. That is exactly what I had measured and could not explain: model written twice, no animation, presentation moving.</p>
<p>Because the class is Objective-C I could hook it on the real devices too. Every one of the 20 SwiftUI cases adds two to four presentation modifiers and sets 42 to 341 values on them, each of those calls off the main thread. The key path follows the property: <code>opacity</code>, <code>bounds</code>, <code>position</code>, or <code>position</code> and <code>transform</code> for scale and rotation. UIKit adds none. The Mac adds none.</p>
<p>Going one level further down, into QuartzCore’s C++, shows what a modifier is for. Each modifier belongs to a group, and a group owns a block of shared memory. On SwiftUI’s thread, every frame, the new value is copied into that shared memory, the group is flushed, and the flush adds a command to Core Animation’s transaction, which the same thread then commits. Here is one frame:</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart TB
  tick[&quot;the display link ticks&quot;] --&gt; evaluate
  subgraph T[&quot;SwiftUI&#39;s own thread&quot;]
    direction TB
    evaluate[&quot;evaluates the animation&lt;br/&gt;at this time&quot;] --&gt; write[&quot;writes the value&lt;br/&gt;into a record&quot;] --&gt; send[&quot;sends two small messages,&lt;br/&gt;with no values in them&quot;]
  end
  subgraph R[&quot;the render server&quot;]
    direction TB
    swap[&quot;swaps the buffer&lt;br/&gt;and reads the value&quot;] --&gt; draw[&quot;draws the layer&quot;]
  end
  memory[&quot;the shared memory&quot;]
  write --&gt; memory
  send --&gt; swap
  memory --&gt; swap
  note[&quot;this half is read from the render server&#39;s code,&lt;br/&gt;I did not watch it run&quot;] -.-&gt; swap
</pre>
</figure>
<h3>The shared memory</h3>
<p>I could reach the group’s shared memory from inside the app, and the disassembly of the render server’s flush function told me where its size and its data pointer sit. So I read it every 4 milliseconds while an opacity animated, on the simulator and on both real devices. It is 114,688 bytes. The first 112 bytes of one reading, from the iPhone 17 Pro Max, are in this picture, coloured by field:</p>
<p><img src="https://aleahim.com/images/blog/how-swiftui-animates/shared-memory-bytes.png" alt="The first 112 bytes of one reading of the shared memory, as captured, coloured by field"></p>
<table><thead><tr><th>Bytes</th><th>Colour</th><th>What it is</th></tr></thead><tbody><tr><td>0 to 3</td><td>violet</td><td>A flags word. Bit 0 flips between readings, as the render server’s flush function flips it.</td></tr><tr><td>4 to 7</td><td>lilac</td><td>The flip flag, equal to that bit.</td></tr><tr><td>8 to 11</td><td>amber</td><td>A sequence number. It only ever rises.</td></tr><tr><td>12 to 15</td><td>grey</td><td>A count: 2, the two modifiers.</td></tr><tr><td>16 to 39</td><td>pale yellow</td><td>Three times, as doubles.</td></tr><tr><td>40 to 47</td><td>teal</td><td>The flags of record 0: <code>0x1</code>.</td></tr><tr><td>48 to 55</td><td>coral</td><td>The value of record 0, a double. It is the animated opacity.</td></tr><tr><td>56 to 63</td><td>dark</td><td>A second double, 0 in every reading.</td></tr><tr><td>64 to 111</td><td>the same</td><td>Records 1 and 2 have the same three fields. Record 2 has flags <code>0x10001</code>.</td></tr></tbody></table>
<p>The values in the records are the animation. Here are two of the records over the first frames of an opacity animation from 0.2 up to 1 over 0.8 seconds, on the iPhone. The record with flags <code>0x10001</code> takes a new value on every frame. The one with flags <code>0x1</code> takes a new value on every other frame, and trails by one frame:</p>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">iPhone 17 Pro Max: two records of the shared memory over the first 12 frames</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="iPhone 17 Pro Max: two records of the shared memory over the first 12 frames"
>
<desc>line chart with 12 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="209.33"
  x2="696"
  y2="209.33"
></line>
<text
  class="td-chart-value"
  x="70"
  y="213.33"
  text-anchor="end"
>0.2</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="116.67"
  x2="696"
  y2="116.67"
></line>
<text
  class="td-chart-value"
  x="70"
  y="120.67"
  text-anchor="end"
>0.4</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>0.6</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<polyline class="td-chart-line td-chart-series-0" points="105.67,132.1 157,124.4 208.33,116.67 259.67,108.93 311,101.19 362.33,93.5 413.67,85.76 465,78.02 516.33,70.33 567.67,62.6 619,54.86 670.33,47.17"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="105.67"
  cy="132.1"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="157"
  cy="124.4"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="208.33"
  cy="116.67"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="259.67"
  cy="108.93"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="311"
  cy="101.19"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="362.33"
  cy="93.5"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="413.67"
  cy="85.76"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="465"
  cy="78.02"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="516.33"
  cy="70.33"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="567.67"
  cy="62.6"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="619"
  cy="54.86"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="670.33"
  cy="47.17"
  r="4"
></circle>
<polyline class="td-chart-line td-chart-series-1" points="105.67,132.1 157,116.67 208.33,116.67 259.67,101.19 311,101.19 362.33,85.76 413.67,85.76 465,70.33 516.33,70.33 567.67,54.86 619,54.86 670.33,39.43"></polyline>
<circle
  class="td-chart-point td-chart-series-1"
  cx="105.67"
  cy="132.1"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="157"
  cy="116.67"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="208.33"
  cy="116.67"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="259.67"
  cy="101.19"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="311"
  cy="101.19"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="362.33"
  cy="85.76"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="413.67"
  cy="85.76"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="465"
  cy="70.33"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="516.33"
  cy="70.33"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="567.67"
  cy="54.86"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="619"
  cy="54.86"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="670.33"
  cy="39.43"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="105.67"
  y="324"
  text-anchor="middle"
>1</text>
<text
  class="td-chart-label"
  x="157"
  y="324"
  text-anchor="middle"
>2</text>
<text
  class="td-chart-label"
  x="208.33"
  y="324"
  text-anchor="middle"
>3</text>
<text
  class="td-chart-label"
  x="259.67"
  y="324"
  text-anchor="middle"
>4</text>
<text
  class="td-chart-label"
  x="311"
  y="324"
  text-anchor="middle"
>5</text>
<text
  class="td-chart-label"
  x="362.33"
  y="324"
  text-anchor="middle"
>6</text>
<text
  class="td-chart-label"
  x="413.67"
  y="324"
  text-anchor="middle"
>7</text>
<text
  class="td-chart-label"
  x="465"
  y="324"
  text-anchor="middle"
>8</text>
<text
  class="td-chart-label"
  x="516.33"
  y="324"
  text-anchor="middle"
>9</text>
<text
  class="td-chart-label"
  x="567.67"
  y="324"
  text-anchor="middle"
>10</text>
<text
  class="td-chart-label"
  x="619"
  y="324"
  text-anchor="middle"
>11</text>
<text
  class="td-chart-label"
  x="670.33"
  y="324"
  text-anchor="middle"
>12</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>frame</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>the record&#39;s value, an opacity</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>updated every frame</text>
<rect
  class="td-chart-series-1"
  x="267.04"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="285.04"
  y="346"
  text-anchor="start"
>updated every other frame</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 1: 0.37</title>
<circle class="td-chart-hit" cx="105.67" cy="132.1" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="4" y="90.1" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="13" y="110.1">updated every frame, 1: 0.37</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 2: 0.38</title>
<circle class="td-chart-hit" cx="157" cy="124.4" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="33.2" y="82.4" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="42.2" y="102.4">updated every frame, 2: 0.38</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 3: 0.4</title>
<circle class="td-chart-hit" cx="208.33" cy="116.67" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="88.63" y="74.67" width="239.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="97.63" y="94.67">updated every frame, 3: 0.4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 4: 0.42</title>
<circle class="td-chart-hit" cx="259.67" cy="108.93" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="135.87" y="66.93" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="144.87" y="86.93">updated every frame, 4: 0.42</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 5: 0.43</title>
<circle class="td-chart-hit" cx="311" cy="101.19" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="187.2" y="59.19" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="196.2" y="79.19">updated every frame, 5: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 6: 0.45</title>
<circle class="td-chart-hit" cx="362.33" cy="93.5" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="238.53" y="51.5" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="247.53" y="71.5">updated every frame, 6: 0.45</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 7: 0.47</title>
<circle class="td-chart-hit" cx="413.67" cy="85.76" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="289.87" y="43.76" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="298.87" y="63.76">updated every frame, 7: 0.47</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 8: 0.48</title>
<circle class="td-chart-hit" cx="465" cy="78.02" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="341.2" y="36.02" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="350.2" y="56.02">updated every frame, 8: 0.48</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 9: 0.5</title>
<circle class="td-chart-hit" cx="516.33" cy="70.33" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="396.63" y="28.33" width="239.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="405.63" y="48.33">updated every frame, 9: 0.5</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 10: 0.52</title>
<circle class="td-chart-hit" cx="567.67" cy="62.6" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="439.77" y="20.6" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="448.77" y="40.6">updated every frame, 10: 0.52</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 11: 0.53</title>
<circle class="td-chart-hit" cx="619" cy="54.86" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="460.2" y="12.86" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="469.2" y="32.86">updated every frame, 11: 0.53</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 12: 0.55</title>
<circle class="td-chart-hit" cx="670.33" cy="47.17" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="460.2" y="5.17" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="469.2" y="25.17">updated every frame, 12: 0.55</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 1: 0.37</title>
<circle class="td-chart-hit" cx="105.67" cy="132.1" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="4" y="90.1" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="13" y="110.1">updated every other frame, 1: 0.37</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 2: 0.4</title>
<circle class="td-chart-hit" cx="157" cy="116.67" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="12.7" y="74.67" width="288.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="21.7" y="94.67">updated every other frame, 2: 0.4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 3: 0.4</title>
<circle class="td-chart-hit" cx="208.33" cy="116.67" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="64.03" y="74.67" width="288.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="73.03" y="94.67">updated every other frame, 3: 0.4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 4: 0.43</title>
<circle class="td-chart-hit" cx="259.67" cy="101.19" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="111.27" y="59.19" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="120.27" y="79.19">updated every other frame, 4: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 5: 0.43</title>
<circle class="td-chart-hit" cx="311" cy="101.19" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="162.6" y="59.19" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="171.6" y="79.19">updated every other frame, 5: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 6: 0.47</title>
<circle class="td-chart-hit" cx="362.33" cy="85.76" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="213.93" y="43.76" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="222.93" y="63.76">updated every other frame, 6: 0.47</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 7: 0.47</title>
<circle class="td-chart-hit" cx="413.67" cy="85.76" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="265.27" y="43.76" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="274.27" y="63.76">updated every other frame, 7: 0.47</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 8: 0.5</title>
<circle class="td-chart-hit" cx="465" cy="70.33" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="320.7" y="28.33" width="288.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="329.7" y="48.33">updated every other frame, 8: 0.5</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 9: 0.5</title>
<circle class="td-chart-hit" cx="516.33" cy="70.33" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="372.03" y="28.33" width="288.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="381.03" y="48.33">updated every other frame, 9: 0.5</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 10: 0.53</title>
<circle class="td-chart-hit" cx="567.67" cy="54.86" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="411" y="12.86" width="305" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="420" y="32.86">updated every other frame, 10: 0.53</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 11: 0.53</title>
<circle class="td-chart-hit" cx="619" cy="54.86" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="411" y="12.86" width="305" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="420" y="32.86">updated every other frame, 11: 0.53</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 12: 0.57</title>
<circle class="td-chart-hit" cx="670.33" cy="39.43" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="411" y="51.43" width="305" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="420" y="71.43">updated every other frame, 12: 0.57</text>
</g>
</g>
</svg>
</div>
</figure>
<p>And on the iPad Pro at 120 Hz, the same, with twice as many frames in the same time:</p>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">iPad Pro, at 120 Hz: the same two records over the first 12 frames</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="iPad Pro, at 120 Hz: the same two records over the first 12 frames"
>
<desc>line chart with 12 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="246.4"
  x2="696"
  y2="246.4"
></line>
<text
  class="td-chart-value"
  x="70"
  y="250.4"
  text-anchor="end"
>0.1</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="190.8"
  x2="696"
  y2="190.8"
></line>
<text
  class="td-chart-value"
  x="70"
  y="194.8"
  text-anchor="end"
>0.2</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="135.2"
  x2="696"
  y2="135.2"
></line>
<text
  class="td-chart-value"
  x="70"
  y="139.2"
  text-anchor="end"
>0.3</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="79.6"
  x2="696"
  y2="79.6"
></line>
<text
  class="td-chart-value"
  x="70"
  y="83.6"
  text-anchor="end"
>0.4</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>0.5</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<polyline class="td-chart-line td-chart-series-0" points="105.67,84.16 157,79.54 208.33,74.93 259.67,70.26 311,65.64 362.33,61.03 413.67,56.36 465,51.74 516.33,47.13 567.67,42.46 619,37.84 670.33,33.23"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="105.67"
  cy="84.16"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="157"
  cy="79.54"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="208.33"
  cy="74.93"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="259.67"
  cy="70.26"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="311"
  cy="65.64"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="362.33"
  cy="61.03"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="413.67"
  cy="56.36"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="465"
  cy="51.74"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="516.33"
  cy="47.13"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="567.67"
  cy="42.46"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="619"
  cy="37.84"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="670.33"
  cy="33.23"
  r="4"
></circle>
<polyline class="td-chart-line td-chart-series-1" points="105.67,79.54 157,79.54 208.33,70.26 259.67,70.26 311,61.03 362.33,61.03 413.67,51.74 465,51.74 516.33,42.46 567.67,42.46 619,33.23 670.33,33.23"></polyline>
<circle
  class="td-chart-point td-chart-series-1"
  cx="105.67"
  cy="79.54"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="157"
  cy="79.54"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="208.33"
  cy="70.26"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="259.67"
  cy="70.26"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="311"
  cy="61.03"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="362.33"
  cy="61.03"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="413.67"
  cy="51.74"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="465"
  cy="51.74"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="516.33"
  cy="42.46"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="567.67"
  cy="42.46"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="619"
  cy="33.23"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="670.33"
  cy="33.23"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="105.67"
  y="324"
  text-anchor="middle"
>1</text>
<text
  class="td-chart-label"
  x="157"
  y="324"
  text-anchor="middle"
>2</text>
<text
  class="td-chart-label"
  x="208.33"
  y="324"
  text-anchor="middle"
>3</text>
<text
  class="td-chart-label"
  x="259.67"
  y="324"
  text-anchor="middle"
>4</text>
<text
  class="td-chart-label"
  x="311"
  y="324"
  text-anchor="middle"
>5</text>
<text
  class="td-chart-label"
  x="362.33"
  y="324"
  text-anchor="middle"
>6</text>
<text
  class="td-chart-label"
  x="413.67"
  y="324"
  text-anchor="middle"
>7</text>
<text
  class="td-chart-label"
  x="465"
  y="324"
  text-anchor="middle"
>8</text>
<text
  class="td-chart-label"
  x="516.33"
  y="324"
  text-anchor="middle"
>9</text>
<text
  class="td-chart-label"
  x="567.67"
  y="324"
  text-anchor="middle"
>10</text>
<text
  class="td-chart-label"
  x="619"
  y="324"
  text-anchor="middle"
>11</text>
<text
  class="td-chart-label"
  x="670.33"
  y="324"
  text-anchor="middle"
>12</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>frame</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>the record&#39;s value, an opacity</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>updated every frame</text>
<rect
  class="td-chart-series-1"
  x="267.04"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="285.04"
  y="346"
  text-anchor="start"
>updated every other frame</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 1: 0.39</title>
<circle class="td-chart-hit" cx="105.67" cy="84.16" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="4" y="42.16" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="13" y="62.16">updated every frame, 1: 0.39</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 2: 0.4</title>
<circle class="td-chart-hit" cx="157" cy="79.54" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="37.3" y="37.54" width="239.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="46.3" y="57.54">updated every frame, 2: 0.4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 3: 0.41</title>
<circle class="td-chart-hit" cx="208.33" cy="74.93" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="84.53" y="32.93" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="93.53" y="52.93">updated every frame, 3: 0.41</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 4: 0.42</title>
<circle class="td-chart-hit" cx="259.67" cy="70.26" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="135.87" y="28.26" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="144.87" y="48.26">updated every frame, 4: 0.42</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 5: 0.43</title>
<circle class="td-chart-hit" cx="311" cy="65.64" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="187.2" y="23.64" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="196.2" y="43.64">updated every frame, 5: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 6: 0.43</title>
<circle class="td-chart-hit" cx="362.33" cy="61.03" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="238.53" y="19.03" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="247.53" y="39.03">updated every frame, 6: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 7: 0.44</title>
<circle class="td-chart-hit" cx="413.67" cy="56.36" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="289.87" y="14.36" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="298.87" y="34.36">updated every frame, 7: 0.44</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 8: 0.45</title>
<circle class="td-chart-hit" cx="465" cy="51.74" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="341.2" y="9.74" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="350.2" y="29.74">updated every frame, 8: 0.45</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 9: 0.46</title>
<circle class="td-chart-hit" cx="516.33" cy="47.13" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="392.53" y="5.13" width="247.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="401.53" y="25.13">updated every frame, 9: 0.46</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 10: 0.47</title>
<circle class="td-chart-hit" cx="567.67" cy="42.46" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="439.77" y="54.46" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="448.77" y="74.46">updated every frame, 10: 0.47</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 11: 0.48</title>
<circle class="td-chart-hit" cx="619" cy="37.84" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="460.2" y="49.84" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="469.2" y="69.84">updated every frame, 11: 0.48</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>updated every frame, 12: 0.48</title>
<circle class="td-chart-hit" cx="670.33" cy="33.23" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="460.2" y="45.23" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="469.2" y="65.23">updated every frame, 12: 0.48</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 1: 0.4</title>
<circle class="td-chart-hit" cx="105.67" cy="79.54" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="4" y="37.54" width="288.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="13" y="57.54">updated every other frame, 1: 0.4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 2: 0.4</title>
<circle class="td-chart-hit" cx="157" cy="79.54" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="12.7" y="37.54" width="288.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="21.7" y="57.54">updated every other frame, 2: 0.4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 3: 0.42</title>
<circle class="td-chart-hit" cx="208.33" cy="70.26" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="59.93" y="28.26" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="68.93" y="48.26">updated every other frame, 3: 0.42</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 4: 0.42</title>
<circle class="td-chart-hit" cx="259.67" cy="70.26" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="111.27" y="28.26" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="120.27" y="48.26">updated every other frame, 4: 0.42</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 5: 0.43</title>
<circle class="td-chart-hit" cx="311" cy="61.03" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="162.6" y="19.03" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="171.6" y="39.03">updated every other frame, 5: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 6: 0.43</title>
<circle class="td-chart-hit" cx="362.33" cy="61.03" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="213.93" y="19.03" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="222.93" y="39.03">updated every other frame, 6: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 7: 0.45</title>
<circle class="td-chart-hit" cx="413.67" cy="51.74" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="265.27" y="9.74" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="274.27" y="29.74">updated every other frame, 7: 0.45</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 8: 0.45</title>
<circle class="td-chart-hit" cx="465" cy="51.74" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="316.6" y="9.74" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="325.6" y="29.74">updated every other frame, 8: 0.45</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 9: 0.47</title>
<circle class="td-chart-hit" cx="516.33" cy="42.46" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="367.93" y="54.46" width="296.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="376.93" y="74.46">updated every other frame, 9: 0.47</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 10: 0.47</title>
<circle class="td-chart-hit" cx="567.67" cy="42.46" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="411" y="54.46" width="305" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="420" y="74.46">updated every other frame, 10: 0.47</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 11: 0.48</title>
<circle class="td-chart-hit" cx="619" cy="33.23" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="411" y="45.23" width="305" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="420" y="65.23">updated every other frame, 11: 0.48</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>updated every other frame, 12: 0.48</title>
<circle class="td-chart-hit" cx="670.33" cy="33.23" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="411" y="45.23" width="305" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="420" y="65.23">updated every other frame, 12: 0.48</text>
</g>
</g>
</svg>
</div>
</figure>
<p>So the rate of the values in the memory follows the display’s refresh rate, on every platform. Why a modifier has three records, and what the two flag values mean, I inferred from their rates; I did not read it from code.</p>
<h3>The messages</h3>
<p>If the values are in shared memory, what does SwiftUI’s thread send the render server on every frame? I put a breakpoint on <code>mach_msg</code> and captured them. Every frame there are two small messages, of 72 and 84 bytes, and every 84 byte message had a 72 byte one within 4 milliseconds. I had guessed the 72 byte one carried a layer’s properties. It does not. Both are the same Core Animation transaction record. Here are the bytes of a real one of each, coloured by field.</p>
<p>The 72 byte message is a transaction with no commands:</p>
<p><img src="https://aleahim.com/images/blog/how-swiftui-animates/message-72.png" alt="A real captured 72 byte message, coloured by field"></p>
<table><thead><tr><th>Bytes</th><th>Colour</th><th>What it is</th></tr></thead><tbody><tr><td>0 to 31</td><td>grey</td><td>The Mach message header (24 bytes) and two words.</td></tr><tr><td>32 to 35</td><td>violet</td><td>The context the message is for.</td></tr><tr><td>36 to 43</td><td>amber</td><td>A time, a double.</td></tr><tr><td>44</td><td>coral</td><td>The marker <code>0x21</code>: a transaction record follows.</td></tr><tr><td>45 to 48</td><td>light coral</td><td>A commit counter.</td></tr><tr><td>49</td><td>grey</td><td>A flags byte, 0 in every message.</td></tr><tr><td>50 to 58</td><td>pale yellow</td><td>The marker <code>0x1e</code> and a second time.</td></tr><tr><td>59 to 67</td><td>lilac</td><td>The marker <code>0x1f</code> and a last double, of a few microseconds.</td></tr><tr><td>68 to 71</td><td>dark</td><td>Zeros.</td></tr></tbody></table>
<p>The 84 byte message is the same record with the reference to the shared memory in front of it:</p>
<p><img src="https://aleahim.com/images/blog/how-swiftui-animates/message-84.png" alt="A real captured 84 byte message, coloured by field"></p>
<table><thead><tr><th>Bytes</th><th>Colour</th><th>What it is</th></tr></thead><tbody><tr><td>0 to 43</td><td>grey, violet, amber</td><td>The same header, context and time as above.</td></tr><tr><td>44 to 57</td><td>teal</td><td>The marker <code>0x24</code>, a 9 byte key, an index byte and three zeros: the reference to the shared memory.</td></tr><tr><td>58</td><td>coral</td><td>The marker <code>0x21</code>.</td></tr><tr><td>59 to 82</td><td>the same</td><td>The commit counter, flags, the two times and the last double, as above, then two bytes of zeros.</td></tr></tbody></table>
<p>I found which function writes each marker byte by scanning QuartzCore’s code for the instruction that stores it. <code>0x21</code>, <code>0x1e</code> and <code>0x1f</code> are all written in <code>CA::Context::commit_transaction</code>, followed by the call that sends the message. <code>0x24</code> is written by <code>CA::Context::commit_command</code>.</p>
<p>Nothing in the per-frame traffic is a property value. The values are in the shared memory, and the messages only say that it was updated. That the render server then swaps the buffer and reads the values each frame I know from reading its code. I could not watch it: a debugger is refused on the render server even in the simulator.</p>
<h2>The control: who runs it</h2>
<p>Two more tests ask what the render server does by itself. The first one stops SwiftUI’s own render thread for half a second instead of blocking the main thread. If the render server ran a SwiftUI animation on its own, the dot would not care. Here is the screen, in the same chart as before, on the real iPad:</p>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">Control, iPad Pro: where the dot was while SwiftUI&#39;s own thread was stopped</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="Control, iPad Pro: where the dot was while SwiftUI&#39;s own thread was stopped"
>
<desc>line chart with 12 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="246.4"
  x2="696"
  y2="246.4"
></line>
<text
  class="td-chart-value"
  x="70"
  y="250.4"
  text-anchor="end"
>0.2</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="190.8"
  x2="696"
  y2="190.8"
></line>
<text
  class="td-chart-value"
  x="70"
  y="194.8"
  text-anchor="end"
>0.4</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="135.2"
  x2="696"
  y2="135.2"
></line>
<text
  class="td-chart-value"
  x="70"
  y="139.2"
  text-anchor="end"
>0.6</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="79.6"
  x2="696"
  y2="79.6"
></line>
<text
  class="td-chart-value"
  x="70"
  y="83.6"
  text-anchor="end"
>0.8</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>1</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<polyline class="td-chart-line td-chart-series-0" points="105.67,246.12 157,226.94 208.33,209.43 259.67,191.91 311,176.62 362.33,157.44 413.67,139.93 465,124.36 516.33,107.12 567.67,89.89 619,72.37 670.33,56.8"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="105.67"
  cy="246.12"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="157"
  cy="226.94"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="208.33"
  cy="209.43"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="259.67"
  cy="191.91"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="311"
  cy="176.62"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="362.33"
  cy="157.44"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="413.67"
  cy="139.93"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="465"
  cy="124.36"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="516.33"
  cy="107.12"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="567.67"
  cy="89.89"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="619"
  cy="72.37"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="670.33"
  cy="56.8"
  r="4"
></circle>
<polyline class="td-chart-line td-chart-series-1" points="105.67,243.06 157,225.83 208.33,208.31 259.67,191.08 311,181.35 362.33,181.35 413.67,181.35 465,121.58 516.33,104.06 567.67,86.83 619,69.31 670.33,53.75"></polyline>
<circle
  class="td-chart-point td-chart-series-1"
  cx="105.67"
  cy="243.06"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="157"
  cy="225.83"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="208.33"
  cy="208.31"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="259.67"
  cy="191.08"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="311"
  cy="181.35"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="362.33"
  cy="181.35"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="413.67"
  cy="181.35"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="465"
  cy="121.58"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="516.33"
  cy="104.06"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="567.67"
  cy="86.83"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="619"
  cy="69.31"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="670.33"
  cy="53.75"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="105.67"
  y="324"
  text-anchor="middle"
>-0.45</text>
<text
  class="td-chart-label"
  x="157"
  y="324"
  text-anchor="middle"
>-0.30</text>
<text
  class="td-chart-label"
  x="208.33"
  y="324"
  text-anchor="middle"
>-0.15</text>
<text
  class="td-chart-label"
  x="259.67"
  y="324"
  text-anchor="middle"
>0.00 *</text>
<text
  class="td-chart-label"
  x="311"
  y="324"
  text-anchor="middle"
>0.15 *</text>
<text
  class="td-chart-label"
  x="362.33"
  y="324"
  text-anchor="middle"
>0.30 *</text>
<text
  class="td-chart-label"
  x="413.67"
  y="324"
  text-anchor="middle"
>0.45 *</text>
<text
  class="td-chart-label"
  x="465"
  y="324"
  text-anchor="middle"
>0.60</text>
<text
  class="td-chart-label"
  x="516.33"
  y="324"
  text-anchor="middle"
>0.75</text>
<text
  class="td-chart-label"
  x="567.67"
  y="324"
  text-anchor="middle"
>0.90</text>
<text
  class="td-chart-label"
  x="619"
  y="324"
  text-anchor="middle"
>1.05</text>
<text
  class="td-chart-label"
  x="670.33"
  y="324"
  text-anchor="middle"
>1.20</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>seconds from the marker, * the main thread was blocked</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>the dot&#39;s place, as a fraction of its travel</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>UIKit</text>
<rect
  class="td-chart-series-1"
  x="153.12"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="171.12"
  y="346"
  text-anchor="start"
>SwiftUI</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.45: 0.2</title>
<circle class="td-chart-hit" cx="105.67" cy="246.12" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="26.97" y="204.12" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="35.97" y="224.12">UIKit, -0.45: 0.2</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.30: 0.27</title>
<circle class="td-chart-hit" cx="157" cy="226.94" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="74.2" y="184.94" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="83.2" y="204.94">UIKit, -0.30: 0.27</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, -0.15: 0.33</title>
<circle class="td-chart-hit" cx="208.33" cy="209.43" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="125.53" y="167.43" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="134.53" y="187.43">UIKit, -0.15: 0.33</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.00 *: 0.4</title>
<circle class="td-chart-hit" cx="259.67" cy="191.91" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="176.87" y="149.91" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="185.87" y="169.91">UIKit, 0.00 *: 0.4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.15 *: 0.45</title>
<circle class="td-chart-hit" cx="311" cy="176.62" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="224.1" y="134.62" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="233.1" y="154.62">UIKit, 0.15 *: 0.45</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.30 *: 0.52</title>
<circle class="td-chart-hit" cx="362.33" cy="157.44" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="275.43" y="115.44" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="284.43" y="135.44">UIKit, 0.30 *: 0.52</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.45 *: 0.58</title>
<circle class="td-chart-hit" cx="413.67" cy="139.93" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="326.77" y="97.93" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="335.77" y="117.93">UIKit, 0.45 *: 0.58</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.60: 0.64</title>
<circle class="td-chart-hit" cx="465" cy="124.36" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="386.3" y="82.36" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="395.3" y="102.36">UIKit, 0.60: 0.64</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.75: 0.7</title>
<circle class="td-chart-hit" cx="516.33" cy="107.12" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="441.73" y="65.12" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="450.73" y="85.12">UIKit, 0.75: 0.7</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 0.90: 0.76</title>
<circle class="td-chart-hit" cx="567.67" cy="89.89" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="488.97" y="47.89" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="497.97" y="67.89">UIKit, 0.90: 0.76</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 1.05: 0.83</title>
<circle class="td-chart-hit" cx="619" cy="72.37" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="540.3" y="30.37" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="549.3" y="50.37">UIKit, 1.05: 0.83</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>UIKit, 1.20: 0.88</title>
<circle class="td-chart-hit" cx="670.33" cy="56.8" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="558.6" y="14.8" width="157.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="567.6" y="34.8">UIKit, 1.20: 0.88</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.45: 0.21</title>
<circle class="td-chart-hit" cx="105.67" cy="243.06" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="14.67" y="201.06" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="23.67" y="221.06">SwiftUI, -0.45: 0.21</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.30: 0.27</title>
<circle class="td-chart-hit" cx="157" cy="225.83" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="66" y="183.83" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="75" y="203.83">SwiftUI, -0.30: 0.27</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, -0.15: 0.34</title>
<circle class="td-chart-hit" cx="208.33" cy="208.31" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="117.33" y="166.31" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="126.33" y="186.31">SwiftUI, -0.15: 0.34</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.00 *: 0.4</title>
<circle class="td-chart-hit" cx="259.67" cy="191.08" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="168.67" y="149.08" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="177.67" y="169.08">SwiftUI, 0.00 *: 0.4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.15 *: 0.43</title>
<circle class="td-chart-hit" cx="311" cy="181.35" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="215.9" y="139.35" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="224.9" y="159.35">SwiftUI, 0.15 *: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.30 *: 0.43</title>
<circle class="td-chart-hit" cx="362.33" cy="181.35" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="267.23" y="139.35" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="276.23" y="159.35">SwiftUI, 0.30 *: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.45 *: 0.43</title>
<circle class="td-chart-hit" cx="413.67" cy="181.35" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="318.57" y="139.35" width="190.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="327.57" y="159.35">SwiftUI, 0.45 *: 0.43</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.60: 0.65</title>
<circle class="td-chart-hit" cx="465" cy="121.58" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="378.1" y="79.58" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="387.1" y="99.58">SwiftUI, 0.60: 0.65</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.75: 0.71</title>
<circle class="td-chart-hit" cx="516.33" cy="104.06" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="429.43" y="62.06" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="438.43" y="82.06">SwiftUI, 0.75: 0.71</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 0.90: 0.77</title>
<circle class="td-chart-hit" cx="567.67" cy="86.83" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="480.77" y="44.83" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="489.77" y="64.83">SwiftUI, 0.90: 0.77</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 1.05: 0.84</title>
<circle class="td-chart-hit" cx="619" cy="69.31" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="532.1" y="27.31" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="541.1" y="47.31">SwiftUI, 1.05: 0.84</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>SwiftUI, 1.20: 0.89</title>
<circle class="td-chart-hit" cx="670.33" cy="53.75" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="542.2" y="11.75" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="551.2" y="31.75">SwiftUI, 1.20: 0.89</text>
</g>
</g>
</svg>
</div>
</figure>
<p>The UIKit dot ignores the stop. The SwiftUI dot stays in one place for 450 to 483 milliseconds, depending on the block, then jumps. The replay shows it, with the red bar:</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 4 / 1;">
<div class="td-embed-frame">
<video class="td-embed-video" controls preload="none" title="The control on the iPad Pro, replayed at half speed: SwiftUI&#39;s own thread stopped">
<source src="https://aleahim.com/images/blog/how-swiftui-animates/replay-control.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</figure>
<p>And the real recordings, on the iPad and the iPhone:</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 1210 / 834;">
<div class="td-embed-frame">
<video class="td-embed-video" controls preload="none" title="A real iPad Pro, SwiftUI, SwiftUI&#39;s own thread stopped">
<source src="https://aleahim.com/images/blog/how-swiftui-animates/ipad-suspend-swiftui.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</figure>
<figure class="td-embed" style="--td-embed-aspect-ratio: 2 / 1;">
<div class="td-embed-frame">
<video class="td-embed-video" controls preload="none" title="A real iPhone 17 Pro Max, SwiftUI, SwiftUI&#39;s own thread stopped">
<source src="https://aleahim.com/images/blog/how-swiftui-animates/iphone-suspend-swiftui.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</figure>
<p>The second test is the render server’s own frame counter, which I read from another thread through a private C function. Blocking the main thread changes nothing for either framework:</p>
<figure class="td-chart td-chart-bar">
<figcaption class="td-chart-caption">Frames the render server drew each second, main thread blocked for 0.5 s</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="Frames the render server drew each second, main thread blocked for 0.5 s"
>
<desc>bar chart with 4 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="209.33"
  x2="696"
  y2="209.33"
></line>
<text
  class="td-chart-value"
  x="70"
  y="213.33"
  text-anchor="end"
>50</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="116.67"
  x2="696"
  y2="116.67"
></line>
<text
  class="td-chart-value"
  x="70"
  y="120.67"
  text-anchor="end"
>100</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>150</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<rect
  class="td-chart-bar td-chart-series-0"
  x="123"
  y="193.21"
  width="32"
  height="108.79"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="277"
  y="192.47"
  width="32"
  height="109.53"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="431"
  y="80.34"
  width="32"
  height="221.66"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="585"
  y="79.97"
  width="32"
  height="222.03"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="157"
  y="193.39"
  width="32"
  height="108.61"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="311"
  y="189.87"
  width="32"
  height="112.13"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="465"
  y="78.3"
  width="32"
  height="223.7"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="619"
  y="80.71"
  width="32"
  height="221.29"
  rx="4"
></rect>
<text
  class="td-chart-label"
  x="157"
  y="324"
  text-anchor="middle"
>iPhone simulator UIKit</text>
<text
  class="td-chart-label"
  x="311"
  y="324"
  text-anchor="middle"
>iPhone simulator SwiftUI</text>
<text
  class="td-chart-label"
  x="465"
  y="324"
  text-anchor="middle"
>iPad Pro UIKit</text>
<text
  class="td-chart-label"
  x="619"
  y="324"
  text-anchor="middle"
>iPad Pro SwiftUI</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>recording</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>frames a second</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>Before</text>
<rect
  class="td-chart-series-1"
  x="163.52"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="181.52"
  y="346"
  text-anchor="start"
>During</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Before, iPhone simulator UIKit: 58.7</title>
<rect class="td-chart-hit" x="123" y="193.21" width="32" height="108.79"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="4" y="155.21" width="313.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="13" y="175.21">Before, iPhone simulator UIKit: 58.7</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Before, iPhone simulator SwiftUI: 59.1</title>
<rect class="td-chart-hit" x="277" y="192.47" width="32" height="109.53"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="128.2" y="154.47" width="329.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="137.2" y="174.47">Before, iPhone simulator SwiftUI: 59.1</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Before, iPad Pro UIKit: 119.6</title>
<rect class="td-chart-hit" x="431" y="80.34" width="32" height="221.66"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="319.1" y="42.34" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="328.1" y="62.34">Before, iPad Pro UIKit: 119.6</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Before, iPad Pro SwiftUI: 119.8</title>
<rect class="td-chart-hit" x="585" y="79.97" width="32" height="222.03"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="443.8" y="41.97" width="272.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="452.8" y="61.97">Before, iPad Pro SwiftUI: 119.8</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>During, iPhone simulator UIKit: 58.6</title>
<rect class="td-chart-hit" x="157" y="193.39" width="32" height="108.61"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="16.4" y="155.39" width="313.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="25.4" y="175.39">During, iPhone simulator UIKit: 58.6</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>During, iPhone simulator SwiftUI: 60.5</title>
<rect class="td-chart-hit" x="311" y="189.87" width="32" height="112.13"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="162.2" y="151.87" width="329.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="171.2" y="171.87">During, iPhone simulator SwiftUI: 60.5</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>During, iPad Pro UIKit: 120.7</title>
<rect class="td-chart-hit" x="465" y="78.3" width="32" height="223.7"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="353.1" y="40.3" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="362.1" y="60.3">During, iPad Pro UIKit: 120.7</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>During, iPad Pro SwiftUI: 119.4</title>
<rect class="td-chart-hit" x="619" y="80.71" width="32" height="221.29"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="443.8" y="42.71" width="272.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="452.8" y="62.71">During, iPad Pro SwiftUI: 119.4</text>
</g>
</g>
</svg>
</div>
</figure>
<p>Stopping SwiftUI’s thread takes the render server’s frames away, for SwiftUI only:</p>
<figure class="td-chart td-chart-bar">
<figcaption class="td-chart-caption">Frames the render server drew each second, SwiftUI&#39;s thread stopped for 0.5 s</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="Frames the render server drew each second, SwiftUI&#39;s thread stopped for 0.5 s"
>
<desc>bar chart with 4 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="209.33"
  x2="696"
  y2="209.33"
></line>
<text
  class="td-chart-value"
  x="70"
  y="213.33"
  text-anchor="end"
>50</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="116.67"
  x2="696"
  y2="116.67"
></line>
<text
  class="td-chart-value"
  x="70"
  y="120.67"
  text-anchor="end"
>100</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>150</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<rect
  class="td-chart-bar td-chart-series-0"
  x="123"
  y="193.02"
  width="32"
  height="108.98"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="277"
  y="190.99"
  width="32"
  height="111.01"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="431"
  y="78.67"
  width="32"
  height="223.33"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="585"
  y="78.86"
  width="32"
  height="223.14"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="157"
  y="193.02"
  width="32"
  height="108.98"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="311"
  y="302"
  width="32"
  height="0"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="465"
  y="81.45"
  width="32"
  height="220.55"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-1"
  x="619"
  y="291.99"
  width="32"
  height="10.01"
  rx="4"
></rect>
<text
  class="td-chart-label"
  x="157"
  y="324"
  text-anchor="middle"
>iPhone simulator UIKit</text>
<text
  class="td-chart-label"
  x="311"
  y="324"
  text-anchor="middle"
>iPhone simulator SwiftUI</text>
<text
  class="td-chart-label"
  x="465"
  y="324"
  text-anchor="middle"
>iPad Pro UIKit</text>
<text
  class="td-chart-label"
  x="619"
  y="324"
  text-anchor="middle"
>iPad Pro SwiftUI</text>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>recording</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>frames a second</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>Before</text>
<rect
  class="td-chart-series-1"
  x="163.52"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="181.52"
  y="346"
  text-anchor="start"
>During</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Before, iPhone simulator UIKit: 58.8</title>
<rect class="td-chart-hit" x="123" y="193.02" width="32" height="108.98"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="4" y="155.02" width="313.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="13" y="175.02">Before, iPhone simulator UIKit: 58.8</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Before, iPhone simulator SwiftUI: 59.9</title>
<rect class="td-chart-hit" x="277" y="190.99" width="32" height="111.01"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="128.2" y="152.99" width="329.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="137.2" y="172.99">Before, iPhone simulator SwiftUI: 59.9</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Before, iPad Pro UIKit: 120.5</title>
<rect class="td-chart-hit" x="431" y="78.67" width="32" height="223.33"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="319.1" y="40.67" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="328.1" y="60.67">Before, iPad Pro UIKit: 120.5</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Before, iPad Pro SwiftUI: 120.4</title>
<rect class="td-chart-hit" x="585" y="78.86" width="32" height="223.14"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="443.8" y="40.86" width="272.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="452.8" y="60.86">Before, iPad Pro SwiftUI: 120.4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>During, iPhone simulator UIKit: 58.8</title>
<rect class="td-chart-hit" x="157" y="193.02" width="32" height="108.98"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="16.4" y="155.02" width="313.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="25.4" y="175.02">During, iPhone simulator UIKit: 58.8</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>During, iPhone simulator SwiftUI: 0</title>
<rect class="td-chart-hit" x="311" y="286" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="174.5" y="264" width="305" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="183.5" y="284">During, iPhone simulator SwiftUI: 0</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>During, iPad Pro UIKit: 119</title>
<rect class="td-chart-hit" x="465" y="81.45" width="32" height="220.55"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="361.3" y="43.45" width="239.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="370.3" y="63.45">During, iPad Pro UIKit: 119</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>During, iPad Pro SwiftUI: 5.4</title>
<rect class="td-chart-hit" x="619" y="281" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="460.2" y="253.99" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="469.2" y="273.99">During, iPad Pro SwiftUI: 5.4</text>
</g>
</g>
</svg>
</div>
</figure>
<p>On the simulator the server went from 59.9 frames a second to none while SwiftUI’s thread was stopped, and on the iPad Pro from 120.4 to 5.4. The UIKit animation was untouched in both. So the render server does not animate a SwiftUI animation by itself. It draws what SwiftUI’s thread sends it, and when that thread stops it has nothing to draw. The iPhone 17 Pro Max’s counter drew 60 frames a second in every run, so it is not an instrument there, and I left it out.</p>
<h2>So which is it</h2>
<p>Both are true, on different platforms.</p>
<table><thead><tr><th></th><th>Mac</th><th>iPhone and iPad</th></tr></thead><tbody><tr><td><code>UIView.animate</code>, <code>animator()</code></td><td>data, the render server runs it</td><td>data, the render server runs it</td></tr><tr><td>SwiftUI built-in animation</td><td>the app writes every pass, on the main thread</td><td>presentation modifiers set from SwiftUI’s own thread, model written twice, no animation</td></tr><tr><td>SwiftUI custom animation callback</td><td>on the main thread</td><td>off the main thread, apart from one to four calls of a case</td></tr><tr><td>Main thread blocked</td><td>the SwiftUI animation stops, the dot waits</td><td>it keeps going at the same speed as UIKit</td></tr><tr><td>SwiftUI’s own thread stopped</td><td>not applicable</td><td>the SwiftUI animation stops, the UIKit one does not</td></tr></tbody></table>
<p>The popular description of SwiftUI as a pull model driven from the main thread is a description of the Mac. And Apple’s sentence from WWDC 2023, that built-in attributes run off the main thread, fits iPhone and iPad and does not fit the Mac.</p>
<h2>What it means for your code</h2>
<p>Three things I would act on, and one I would not.</p>
<ol><li><p><strong>On the Mac, SwiftUI animations share the main thread with everything else.</strong> A slow <code>body</code>, a long layout, a synchronous call, and the animation stutters, where a Core Animation animation would have kept moving. For motion that must not stutter on the Mac, the framework’s own animation is the safer choice.</p></li><li><p><strong>A custom animation’s <code>animate</code> mostly runs off the main thread on iPhone and iPad.</strong> If it touches main-actor state, that is a data race waiting to happen. I measured it with a callback that only counts, so I know where it runs, not what breaks.</p></li><li><p><strong>Do not generalize from one platform.</strong> Whatever you read about how SwiftUI animates, check which platform it was measured on. I nearly did not.</p></li></ol>
<p>And the one I would not: do not build on the private classes in this post. I used them to look, nothing else.</p>
<h2>What I got wrong on the way</h2>
<p>This is the part worth reading twice, because the mistakes are easy.</p>
<p>My first iOS runs read model values only and showed almost nothing happening. The motion only appeared when I read presentation values too.</p>
<p>Then I counted 54 setter calls for an opacity animation on the iPhone where the app made 4. Reading <code>layer.presentation()</code> builds a copy of the layer, and building the copy calls the setters I was hooking. I was counting my own probe. The hooks now stand down while the probe reads.</p>
<p>I first tested the blocked main thread by reading presentation values from a background thread. It said UIKit’s own animation had stalled too, which I knew was false. A measurement that fails on the case whose answer you know does not measure what you wanted, so I dropped it and counted callbacks and then screens instead.</p>
<p>I moved a threshold after seeing the data, from 20 different values to 10, because two iPhone cases fell at 19 and 20 on a 120 Hz screen. It changes those two verdicts only.</p>
<p>My first colour thresholds for finding the red dot sat on the edge of the iPhone’s red and found it in only some frames, which showed as impossible speeds. I widened them and recorded all eight runs again.</p>
<p>And I guessed that the 72 byte message carried a layer’s properties. Decoding it showed it does not.</p>
<h2>What I do not know</h2>
<ul><li><p>Where the last number in each frame’s record comes from (a few microseconds), what the command is called, and why each modifier has three records in the shared memory.</p></li><li><p>Stalls shorter than about 35 milliseconds on a real device: the recording I could take is 60 frames a second, also on the 120 Hz iPad.</p></li><li><p><code>scaleEffect</code> and <code>rotationEffect</code> with the main thread blocked, on both platforms. The blocked test only covers the custom animation.</p></li><li><p>How many messages SwiftUI sends per frame on the Mac. I counted them on the iPhone simulator, not on the Mac.</p></li><li><p>Transitions, matched geometry, keyframe and phase animators, <code>Canvas</code> and <code>TimelineView</code>. I probed five properties and four kinds of animation, in a hosted view with a fixed layout.</p></li><li><p>Whether the Mac differs on a newer build than 27.0.1.</p></li></ul>
<p>The probe, the recordings and the decoded bytes are in a private repository for now. Every number in this post is in the charts and tables above, taken from those recordings.</p>]]></content:encoded>
</item>
<item>
<title>Modifier Order Is Matrix Order</title>
<link>https://aleahim.com/blog/swiftui-modifier-order/</link>
<guid isPermaLink="true">https://aleahim.com/blog/swiftui-modifier-order/</guid>
<pubDate>Sat, 03 Oct 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>SwiftUI modifiers compose in the same order as Core Graphics transforms, read from the other end, and offset snaps to the pixel grid so a later scale multiplies its rounding, measured by rendering eight modifier chains against closed-form matrix math</description>
<content:encoded><![CDATA[<h1>Modifier Order Is Matrix Order</h1>
<p>Every SwiftUI developer learns early that modifier order matters. <code>.padding().background(Color.red)</code> is not <code>.background(Color.red).padding()</code>. It is taught as folklore: try both, keep the one that looks right.</p>
<p>For the transform modifiers, <code>offset</code>, <code>rotationEffect</code>, and <code>scaleEffect</code>, it is not folklore. It is matrix order, the same law that governs a <code>CGContext</code>, read from the other end of the chain. And there is one rounding rule hiding inside <code>offset</code> that the algebra does not predict, which I found because a measurement refused to agree with my own prediction.</p>
<p>Here is the smallest version. The same marker, the same two modifiers, written in two orders:</p>
<pre><code class="language-swift"><span class="tok-comment">// Orange, on the left.</span>
<span class="tok-type">Rectangle</span>()<span class="tok-operator">.</span><span class="tok-function">fill</span>(<span class="tok-operator">.</span>orange)<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">120</span>, height<span class="tok-operator">:</span> <span class="tok-number">60</span>)
    <span class="tok-operator">.</span><span class="tok-function">offset</span>(x<span class="tok-operator">:</span> <span class="tok-number">160</span>)
    <span class="tok-operator">.</span><span class="tok-function">rotationEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">30</span>))

<span class="tok-comment">// Teal, on the right.</span>
<span class="tok-type">Rectangle</span>()<span class="tok-operator">.</span><span class="tok-function">fill</span>(<span class="tok-operator">.</span>teal)<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">120</span>, height<span class="tok-operator">:</span> <span class="tok-number">60</span>)
    <span class="tok-operator">.</span><span class="tok-function">rotationEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">30</span>))
    <span class="tok-operator">.</span><span class="tok-function">offset</span>(x<span class="tok-operator">:</span> <span class="tok-number">160</span>)</code></pre>
<p><img src="https://aleahim.com/images/blog/swiftui-modifier-order/offset-rotate.png" alt="Two markers from the same two modifiers in opposite orders, rendered by SwiftUI"></p>
<p><em>Rendered by SwiftUI’s <code>ImageRenderer</code>. (<code>.orange</code> and <code>.teal</code> are shorthand here; the exact RGB values are in the program at the end.) The grey rectangle on each side is where the marker would sit with no modifiers. Orange, offset then rotated, swings around the view’s centre. Teal, rotated then offset, spins in place and slides straight right.</em></p>
<p>Let me say the finding precisely, because the imprecise version is wrong. Do not say “SwiftUI applies modifiers bottom to top.” Say:</p>
<blockquote><p>In a chain of SwiftUI’s transform effects, the one written first, the one closest to the view, is applied to the content first. That is the same rule as Core Graphics, where the transform written last, the one closest to the drawing, is applied to the points first.</p></blockquote>
<p>Both are one sentence: <strong>the operation closest to the content happens first.</strong> Core Graphics reads it bottom to top. SwiftUI reads it top to bottom.</p>
<p>This post is the SwiftUI half of a pair. The Core Graphics half, with the full derivation of the matrix, is <a href="https://appleuiinsider.com/issues/order-matters/">Issue 2 of Apple UI Insider</a>. Here I check the SwiftUI side by rendering real views and measuring them, and I report the one place where the clean algebra needs a correction.</p>
<h2>What the Documentation Promises</h2>
<p>Apple’s documentation says the pieces that make this work. It is worth reading them as a set, because together they are the model:</p>
<ul><li><p><code>offset(x:y:)</code>: “Offset this view by the specified horizontal and vertical distances.” And: “The original dimensions of the view aren’t changed by offsetting the contents.”</p></li><li><p><code>rotationEffect(_:anchor:)</code>: “Rotates a view’s rendered output in two dimensions around the specified point.” It “has no effect on the view’s frame.” The anchor is “a unit point within the view about which to perform the rotation.”</p></li><li><p><code>scaleEffect(_:anchor:)</code>: “Scales this view’s rendered output by the given amount … relative to an anchor point.”</p></li><li><p><code>position(_:)</code>: “Positions the center of this view at the specified point in its parent’s coordinate space.”</p></li></ul>
<p>Three consequences follow. These modifiers act on <strong>rendered output</strong>, not on layout, so they never make room for themselves. Each rotates or scales about an <strong>anchor inside the view’s frame</strong>, and the frame is the layout frame at that point in the chain, which is why <code>frame</code> changes where an anchor is. And the Core Graphics side is documented as <code>CGContext.concatenate(_:)</code>, “Transforms the user coordinate system in a context using a specified matrix”, with <code>translateBy</code>, <code>rotate</code>, and <code>scaleBy</code> as shorthand for the common matrices.</p>
<p>So the model is a matrix per modifier, each about its own anchor, composed in some order. The only open question is the order. Test it.</p>
<h2>The Witness</h2>
<p>The test has no SwiftUI knowledge in the prediction. Each experiment renders one 120 by 60 marker with <code>ImageRenderer</code>, finds where its pixels landed, and compares that with a closed-form prediction built from <code>CGAffineTransform</code>:</p>
<ol><li><p>Write each modifier as a matrix about the marker’s own centre: a shift, a rotation by 30 degrees, a stretch, or a rotation about a corner anchor.</p></li><li><p>Compose them with the first-written modifier applied first.</p></li><li><p>Predict where the marker’s centre goes, how much area it covers, and its second moments, which are what tell a rotation from a shear.</p></li><li><p>Measure the same three things in the rendered pixels. Each pixel’s coverage is how far its colour lies along the line from the background to the marker colour, so anti-aliased edges count fractionally.</p></li></ol>
<p>Eight chains, in four pairs. The second member of each pair is the same two modifiers swapped, and that matters twice: it is the experiment, and it is the <strong>control</strong>. If the measurement could not tell a chain from its swapped partner, it would prove nothing, so the last column is how far the <em>partner’s</em> prediction misses the measured result.</p>
<table><thead><tr><th>Chain, in the order written</th><th>Centre lands at</th><th>Centre error</th><th>Shape error</th><th>The swapped partner misses by</th></tr></thead><tbody><tr><td><code>.offset(x: 160)</code> then <code>.rotationEffect(30°)</code></td><td>(538.6, 305.0)</td><td>0.001 px</td><td>0.0318%</td><td>82.8 px</td></tr><tr><td><code>.rotationEffect(30°)</code> then <code>.offset(x: 160)</code></td><td>(560.0, 225.0)</td><td>0.000 px</td><td>0.0148%</td><td>82.8 px</td></tr><tr><td><code>.offset(x: 80)</code> then <code>.scaleEffect(2)</code></td><td>(560.0, 225.0)</td><td>0.000 px</td><td>0.0000%</td><td>80.0 px</td></tr><tr><td><code>.scaleEffect(2)</code> then <code>.offset(x: 80)</code></td><td>(480.0, 225.0)</td><td>0.000 px</td><td>0.0000%</td><td>80.0 px</td></tr><tr><td><code>.scaleEffect(x: 2)</code> then <code>.rotationEffect(30°)</code></td><td>(400.0, 225.0)</td><td>0.000 px</td><td>0.0050%</td><td>shape off by 31.8%</td></tr><tr><td><code>.rotationEffect(30°)</code> then <code>.scaleEffect(x: 2)</code></td><td>(400.0, 225.0)</td><td>0.000 px</td><td>0.0043%</td><td>shape off by 30.0%</td></tr><tr><td><code>.rotationEffect(30°, anchor: .topLeading)</code> then <code>.frame(300 × 200)</code></td><td>(377.0, 251.0)</td><td>0.001 px</td><td>0.0198%</td><td>59.0 px</td></tr><tr><td><code>.frame(300 × 200)</code> then <code>.rotationEffect(30°, anchor: .topLeading)</code></td><td>(329.9, 286.6)</td><td>0.001 px</td><td>0.0307%</td><td>59.0 px</td></tr></tbody></table>
<p><em>Measured on macOS 27.0.1 (Build 26A434), <code>ImageRenderer</code> at scale 1, 8-bit sRGB. Shape error is the largest second-moment difference as a percentage of the larger predicted variance.</em></p>
<p>The worst centre error across all eight is <strong>0.0009 pixels</strong>. The worst shape error is 0.03%. The swapped partner misses by 59 to 83 pixels, or by 30 to 32 percent of the shape. The measurement can tell the two orders apart by a margin of three to five orders of magnitude, and in each case the first-written-first prediction wins. Each pair deserves its own picture.</p>
<h2>The Offset Gets Scaled</h2>
<p><code>.offset(x: 80).scaleEffect(2)</code> lands at x = 560. <code>.scaleEffect(2).offset(x: 80)</code> lands at x = 480. The scale after the offset multiplies the offset: 80 points of shift becomes 160. The scale before it leaves the offset alone, because by the time the offset runs, the marker is already big and the shift is in parent points.</p>
<p><img src="https://aleahim.com/images/blog/swiftui-modifier-order/offset-scale.png" alt="Offset then scale, and scale then offset"></p>
<p><em>Coral: <code>.offset(x: 80).scaleEffect(2)</code>. Blue: <code>.scaleEffect(2).offset(x: 80)</code>. Grey: the unmodified marker.</em></p>
<p>Here it is moving. The offset sweeps from 0 to 80 points and back, in whole points, for a reason the last section explains. The coral marker travels twice as far as the blue one for the same number.</p>
<p><img src="https://aleahim.com/images/blog/swiftui-modifier-order/scale-offset-sweep.gif" alt="Offset sweep with scale, SwiftUI render"></p>
<p><em>Every frame of this animation, all 72, was measured against the algebra: worst centre error 0.0000 pixels. Full-quality video: <a href="https://aleahim.com/images/blog/swiftui-modifier-order/scale-offset-sweep.mp4">MP4</a>.</em></p>
<h2>Rotate Then Stretch Is a Shear</h2>
<p>Stretch a rectangle to twice its width with <code>.scaleEffect(x: 2, y: 1)</code> and rotate it 30 degrees. Written scale then rotate, the stretch happens first along the rectangle’s own width, and the rectangle then turns: it stays a rectangle. Written rotate then scale, the rotation happens first and the stretch second, along the page’s x axis: the rectangle shears into a parallelogram.</p>
<p><img src="https://aleahim.com/images/blog/swiftui-modifier-order/scale-rotate.png" alt="A stretched rotated rectangle and a sheared parallelogram"></p>
<p><em>Yellow: <code>.scaleEffect(x: 2).rotationEffect(.degrees(30))</code>. Violet: <code>.rotationEffect(.degrees(30)).scaleEffect(x: 2)</code>. The centre is the same in both, which is why the table’s control for this pair is the shape, not the position.</em></p>
<p>Both orders cover the same area and sit at the same centre. Only the second moments tell them apart, and they differ by 30 percent. This is the identical result to the Core Graphics case in the newsletter, with the written order mirrored.</p>
<h2>The Anchor Lives in the Frame at That Point in the Chain</h2>
<p><code>rotationEffect(_:anchor:)</code> rotates about a unit point of the view. But which view? The one you have built <em>so far</em>. Put a <code>frame(width: 300, height: 200)</code> before the rotation and the anchor <code>.topLeading</code> is the top-left corner of the 300 by 200 frame. Put it after, and it is the top-left corner of the marker.</p>
<pre><code class="language-swift"><span class="tok-comment">// Pivots on the marker's own top-left corner.</span>
marker<span class="tok-operator">.</span><span class="tok-function">rotationEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">30</span>), anchor<span class="tok-operator">:</span> <span class="tok-operator">.</span>top<span class="tok-type">Leading</span>)<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">300</span>, height<span class="tok-operator">:</span> <span class="tok-number">200</span>)

<span class="tok-comment">// Pivots on the frame's top-left corner, 90 points left and 70 points up of the marker's own.</span>
marker<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">300</span>, height<span class="tok-operator">:</span> <span class="tok-number">200</span>)<span class="tok-operator">.</span><span class="tok-function">rotationEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">30</span>), anchor<span class="tok-operator">:</span> <span class="tok-operator">.</span>top<span class="tok-type">Leading</span>)</code></pre>
<p><img src="https://aleahim.com/images/blog/swiftui-modifier-order/anchor-frame.png" alt="The same rotation about two different pivots"></p>
<p><em>Green pivots on the marker’s own corner and lands at (377.0, 251.0). Pink pivots on the frame’s corner and lands at (329.9, 286.6). The outlines are the 300 by 200 frame. The grey rectangle is the unrotated marker.</em></p>
<p>The documentation said this in two separate places: <code>rotationEffect</code> does not change the frame, and the anchor is within the view. Together they mean the order of <code>frame</code> and <code>rotationEffect</code> moves the pivot. The measurement puts a number on it: 59.0 pixels.</p>
<h2>Same Words, Opposite Behaviour</h2>
<p>Here is the part that catches people who already know Core Graphics. Take the rotation sweep from the newsletter, where translate then rotate spins the arm in place. The SwiftUI version, with the same words in the same order, does the opposite:</p>
<p><img src="https://aleahim.com/images/blog/swiftui-modifier-order/rotation-sweep.gif" alt="Rotation sweep: offset then rotate orbits, rotate then offset spins in place"></p>
<p><em>Orange: <code>.offset(x: 200).rotationEffect(angle)</code>, which orbits the pale dot. Teal: <code>.rotationEffect(angle).offset(x: 200)</code>, which spins in place while sitting 200 points to the right. All 72 frames measured: worst centre error 0.0102 pixels. Full-quality video: <a href="https://aleahim.com/images/blog/swiftui-modifier-order/rotation-sweep.mp4">MP4</a>.</em></p>
<p>In Core Graphics, “translate, rotate” means rotate-then-translate on the points, which spins in place. In SwiftUI, “offset, rotate” means offset-then-rotate on the content, which orbits. The words are the same. The rule, closest to the content first, is the same. The reading direction is mirrored, so the behaviour is too.</p>
<h2>SwiftUI and Core Graphics Draw the Same Pixels</h2>
<p>The witness also draws each prediction with Core Graphics, as one <code>concatenate</code> of the same matrix, and compares it with what SwiftUI rendered.</p>
<p>Of 360,000 pixels per image, SwiftUI and Core Graphics differ in 440 to 737 on the rotated chains, all on anti-aliased edges, with a mean difference between 0.0006% and 0.0017% of full scale. On the two chains that are only an offset and an integer scale, the two renderings are identical, 0 pixels, byte for byte.</p>
<p>That is a second, independent confirmation. The prediction was built from <code>CGAffineTransform</code> and drawn by Core Graphics. SwiftUI never saw it. They agree to the pixel.</p>
<h2><code>.offset</code> Snaps to the Pixel Grid</h2>
<p>Now the correction.</p>
<p>My first animation of the offset-and-scale pair did not agree with the algebra. Not by much: the worst frame was off by 0.97 pixels, in a scene where everything else was within 0.01. I assumed my measurement was leaking a neighbouring shape into the tally, because that is what had gone wrong earlier in the same project. I fixed that and the 0.97 stayed. So I stopped assuming and asked directly: where does SwiftUI put a view offset by a fractional amount?</p>
<table><thead><tr><th>Requested</th><th>At render scale 1</th><th>At scale 2</th><th>At scale 3</th></tr></thead><tbody><tr><td>-10.50</td><td>-10.000</td><td>-10.500</td><td>-10.333</td></tr><tr><td>-0.60</td><td>-1.000</td><td>-0.500</td><td>-0.667</td></tr><tr><td>-0.50</td><td>0.000</td><td>-0.500</td><td>-0.333</td></tr><tr><td>-0.40</td><td>0.000</td><td>-0.500</td><td>-0.333</td></tr><tr><td>0.20</td><td>0.000</td><td>0.000</td><td>0.333</td></tr><tr><td>0.25</td><td>0.000</td><td>0.500</td><td>0.333</td></tr><tr><td>0.50</td><td>1.000</td><td>0.500</td><td>0.667</td></tr><tr><td>0.75</td><td>1.000</td><td>1.000</td><td>0.667</td></tr><tr><td>10.30</td><td>10.000</td><td>10.500</td><td>10.333</td></tr><tr><td>10.50</td><td>11.000</td><td>10.500</td><td>10.667</td></tr></tbody></table>
<p><em>Measured: how far <code>.offset(x:)</code> actually moved a marker, in points. Rows are a subset of the full run printed by the program at the end of this post.</em></p>
<p><code>.offset</code> rounds its amount to the <strong>device pixel grid</strong>: whole points at scale 1, halves at scale 2, thirds at scale 3, with exact ties rounding up. And it does that <em>before</em> any modifier written after it sees the result.</p>
<p>Which is the correction the algebra needs. A scale after the offset multiplies the rounding, not just the offset:</p>
<table><thead><tr><th>Requested</th><th><code>.offset</code>, <code>.scaleEffect(2)</code> lands</th><th>Algebra says</th><th><code>.scaleEffect(2)</code>, <code>.offset</code> lands</th><th>Algebra says</th></tr></thead><tbody><tr><td>0.25</td><td>0.000</td><td>0.50</td><td>0.000</td><td>0.25</td></tr><tr><td>0.50</td><td>2.000</td><td>1.00</td><td>1.000</td><td>0.50</td></tr><tr><td>0.75</td><td>2.000</td><td>1.50</td><td>1.000</td><td>0.75</td></tr><tr><td>10.30</td><td>20.000</td><td>20.60</td><td>10.000</td><td>10.30</td></tr><tr><td>10.50</td><td>22.000</td><td>21.00</td><td>11.000</td><td>10.50</td></tr><tr><td>79.60</td><td>160.000</td><td>159.20</td><td>80.000</td><td>79.60</td></tr></tbody></table>
<p><em>Measured at render scale 1, in points.</em> Ask for half a point before a scale of 2 and you get two. The algebra said one.</p>
<p>Rotation did not show this. The first chain in the table above lands at (538.6, 305.0), a fractional position, within 0.001 pixels of the unrounded prediction, so the result of a rotation is not snapped to the grid. The rounding belongs to <code>offset</code>. I only tested rotation by 30 degrees and scale by 2, including by 2 along one axis, so I will not claim more than that.</p>
<h2>Proof Status</h2>
<p>Following the discipline from <a href="https://aleahim.com/blog/the-swiftui-oracle/">The SwiftUI Oracle</a>, the claim is split into labeled evidence, because “it looks right” is not a result:</p>
<table><thead><tr><th>Claim</th><th>Status</th><th>Evidence</th></tr></thead><tbody><tr><td>Transform modifiers act on rendered output and do not change the view’s frame.</td><td>documented</td><td><code>offset(x:y:)</code>: “The original dimensions of the view aren’t changed”. <code>rotationEffect(_:anchor:)</code>: “no effect on the view’s frame”.</td></tr><tr><td>An anchor is a point within the view at that position in the chain.</td><td>documented, witnessed</td><td><code>rotationEffect</code> documents the anchor as “a unit point within the view”. The <code>frame</code> pair moves the pivot, centre 59.0 px apart.</td></tr><tr><td>The modifier written first is applied to the content first.</td><td>witnessed</td><td>Eight chains: worst centre error 0.0009 px, worst shape error 0.0318%.</td></tr><tr><td>Reading the chain the other way is detectably wrong.</td><td>witnessed</td><td>The swapped partner of each chain misses by 59.0 to 82.8 px, or 30.0 to 31.8% of the shape.</td></tr><tr><td>SwiftUI’s render equals Core Graphics drawing the same matrix.</td><td>witnessed</td><td>0 to 737 differing pixels of 360,000, mean difference at most 0.0017% of full scale.</td></tr><tr><td><code>.offset</code> is rounded to the render scale’s pixel grid, ties up, before later modifiers.</td><td>witnessed</td><td>Offset alone at render scales 1, 2, and 3, and offset before <code>.scaleEffect(2)</code>. Not mentioned in the documentation pages I read.</td></tr><tr><td>The same rounding happens in a live window on screen.</td><td>not measured</td><td>Everything here is <code>ImageRenderer</code> output. I did not capture on-screen frames, so I make no claim about them.</td></tr><tr><td>The same order law holds for other modifiers.</td><td>not measured</td><td><code>padding</code>, <code>scaledToFit</code>, <code>GeometryEffect</code>, and the 3D effects were not tested.</td></tr></tbody></table>
<p>Every measured number in this post comes from macOS 27.0.1 (Build 26A434) with Swift 6.4, <code>ImageRenderer</code> at scale 1 unless noted, rendering into 8-bit sRGB. The Core Graphics twin is drawn into a bitmap flipped so y points down, as it does in SwiftUI.</p>
<h2>What To Do With This</h2>
<p>Four rules fall out of the measurements, and none is folklore:</p>
<ol><li><p>Read a chain from the view outward. The first modifier happens first.</p></li><li><p>Want an offset in the parent’s points, whatever you scale? Put <code>.offset</code> <strong>after</strong> the scale.</p></li><li><p>Want it multiplied by the scale on purpose? Put it <strong>before</strong>. And give it numbers the pixel grid can hold, or expect it to be rounded and then multiplied.</p></li><li><p>Where a pivot matters, a <code>frame</code> before the rotation changes it. Decide which rectangle you mean.</p></li></ol>
<h2>Run It Yourself</h2>
<p>Two standalone programs, no packages and no project. Both render with <code>ImageRenderer</code>, measure the pixels, and print the tables above. Save each as its own file and run, for example, <code>xcrun swiftc -O witness.swift -o witness &amp;&amp; ./witness</code>.</p>
<p>The order witness, 187 lines, prints the eight-chain table:</p>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">AppKit</span>
<span class="tok-keyword">import</span> <span class="tok-type">SwiftUI</span>

<span class="tok-comment">// Witness: does a SwiftUI modifier chain compose in the order the algebra says?</span>
<span class="tok-comment">// Each experiment renders one 120 x 60 marker with real SwiftUI (ImageRenderer),</span>
<span class="tok-comment">// finds where its pixels landed, and compares that with a closed-form prediction</span>
<span class="tok-comment">// made from CGAffineTransform. Nothing here reads the SwiftUI result to build the</span>
<span class="tok-comment">// prediction.</span>

<span class="tok-keyword">struct</span> <span class="tok-type">RGB</span> { <span class="tok-keyword">let</span> r<span class="tok-operator">:</span> <span class="tok-type">Int</span>, g<span class="tok-operator">:</span> <span class="tok-type">Int</span>, b<span class="tok-operator">:</span> <span class="tok-type">Int</span> }
<span class="tok-keyword">let</span> background <span class="tok-operator">=</span> <span class="tok-type">RGB</span>(r<span class="tok-operator">:</span> <span class="tok-number">14</span>, g<span class="tok-operator">:</span> <span class="tok-number">16</span>, b<span class="tok-operator">:</span> <span class="tok-number">24</span>)
<span class="tok-keyword">let</span> canv<span class="tok-keyword">as</span> <span class="tok-operator">=</span> <span class="tok-type">CGSize</span>(width<span class="tok-operator">:</span> <span class="tok-number">800</span>, height<span class="tok-operator">:</span> <span class="tok-number">450</span>)
<span class="tok-keyword">let</span> center <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span> <span class="tok-number">400</span>, y<span class="tok-operator">:</span> <span class="tok-number">225</span>)
<span class="tok-keyword">let</span> marker<span class="tok-type">Size</span> <span class="tok-operator">=</span> <span class="tok-type">CGSize</span>(width<span class="tok-operator">:</span> <span class="tok-number">120</span>, height<span class="tok-operator">:</span> <span class="tok-number">60</span>)

<span class="tok-keyword">func</span> <span class="tok-function">color</span>(_ c<span class="tok-operator">:</span> <span class="tok-type">RGB</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Color</span> { <span class="tok-type">Color</span>(red<span class="tok-operator">:</span> <span class="tok-type">Double</span>(c<span class="tok-operator">.</span>r) <span class="tok-operator">/</span> <span class="tok-number">255</span>, green<span class="tok-operator">:</span> <span class="tok-type">Double</span>(c<span class="tok-operator">.</span>g) <span class="tok-operator">/</span> <span class="tok-number">255</span>, blue<span class="tok-operator">:</span> <span class="tok-type">Double</span>(c<span class="tok-operator">.</span>b) <span class="tok-operator">/</span> <span class="tok-number">255</span>) }
<span class="tok-keyword">func</span> <span class="tok-function">marker</span>(_ c<span class="tok-operator">:</span> <span class="tok-type">RGB</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-keyword">some</span> <span class="tok-type">View</span> { <span class="tok-type">Rectangle</span>()<span class="tok-operator">.</span><span class="tok-function">fill</span>(<span class="tok-function">color</span>(c))<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> marker<span class="tok-type">Size</span><span class="tok-operator">.</span>width, height<span class="tok-operator">:</span> marker<span class="tok-type">Size</span><span class="tok-operator">.</span>height) }

<span class="tok-comment">// Transforms about the marker's own centre, applied to points first-to-last.</span>
<span class="tok-keyword">let</span> rotate<span class="tok-number">30</span> <span class="tok-operator">=</span> <span class="tok-type">CGAffineTransform</span>(rotation<span class="tok-type">Angle</span><span class="tok-operator">:</span> <span class="tok-operator">.</span>pi <span class="tok-operator">/</span> <span class="tok-number">6</span>)
<span class="tok-keyword">func</span> <span class="tok-function">shift</span>(_ x<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>, _ y<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">CGAffineTransform</span> { <span class="tok-type">CGAffineTransform</span>(translation<span class="tok-type">X</span><span class="tok-operator">:</span> x, y<span class="tok-operator">:</span> y) }
<span class="tok-keyword">func</span> <span class="tok-function">stretch</span>(_ x<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>, _ y<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">CGAffineTransform</span> { <span class="tok-type">CGAffineTransform</span>(scale<span class="tok-type">X</span><span class="tok-operator">:</span> x, y<span class="tok-operator">:</span> y) }
<span class="tok-keyword">func</span> <span class="tok-function">about</span>(_ anchor<span class="tok-operator">:</span> <span class="tok-type">CGPoint</span>, _ t<span class="tok-operator">:</span> <span class="tok-type">CGAffineTransform</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">CGAffineTransform</span> {
    <span class="tok-function">shift</span>(<span class="tok-operator">-</span>anchor<span class="tok-operator">.</span>x, <span class="tok-operator">-</span>anchor<span class="tok-operator">.</span>y)<span class="tok-operator">.</span><span class="tok-function">concatenating</span>(t)<span class="tok-operator">.</span><span class="tok-function">concatenating</span>(<span class="tok-function">shift</span>(anchor<span class="tok-operator">.</span>x, anchor<span class="tok-operator">.</span>y))
}

<span class="tok-keyword">struct</span> <span class="tok-type">Experiment</span> {
    <span class="tok-keyword">let</span> name<span class="tok-operator">:</span> <span class="tok-type">String</span>
    <span class="tok-keyword">let</span> fill<span class="tok-operator">:</span> <span class="tok-type">RGB</span>
    <span class="tok-keyword">let</span> view<span class="tok-operator">:</span> (<span class="tok-type">RGB</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">AnyView</span>          <span class="tok-comment">// the marker with its modifier chain</span>
    <span class="tok-keyword">let</span> steps<span class="tok-operator">:</span> [<span class="tok-type">CGAffineTransform</span>]      <span class="tok-comment">// one per modifier, in the order they are written</span>
    <span class="tok-comment">/// Closed form: the modifier written first (closest to the view) applies first.</span>
    <span class="tok-keyword">var</span> answer<span class="tok-operator">:</span> <span class="tok-type">CGAffineTransform</span> { steps<span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-operator">.</span>identity) { $<span class="tok-number">0.</span><span class="tok-function">concatenating</span>($<span class="tok-number">1</span>) } }
}

<span class="tok-keyword">let</span> experiments<span class="tok-operator">:</span> [<span class="tok-type">Experiment</span>] <span class="tok-operator">=</span> [
    <span class="tok-type">Experiment</span>(name<span class="tok-operator">:</span> <span class="tok-string">".offset(x: 160), .rotationEffect(30)"</span>, fill<span class="tok-operator">:</span> <span class="tok-type">RGB</span>(r<span class="tok-operator">:</span> <span class="tok-number">250</span>, g<span class="tok-operator">:</span> <span class="tok-number">140</span>, b<span class="tok-operator">:</span> <span class="tok-number">31</span>),
               view<span class="tok-operator">:</span> { <span class="tok-type">AnyView</span>(<span class="tok-function">marker</span>($<span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">offset</span>(x<span class="tok-operator">:</span> <span class="tok-number">160</span>, y<span class="tok-operator">:</span> <span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">rotationEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">30</span>))) },
               steps<span class="tok-operator">:</span> [<span class="tok-function">shift</span>(<span class="tok-number">160</span>, <span class="tok-number">0</span>), rotate<span class="tok-number">30</span>]),
    <span class="tok-type">Experiment</span>(name<span class="tok-operator">:</span> <span class="tok-string">".rotationEffect(30), .offset(x: 160)"</span>, fill<span class="tok-operator">:</span> <span class="tok-type">RGB</span>(r<span class="tok-operator">:</span> <span class="tok-number">26</span>, g<span class="tok-operator">:</span> <span class="tok-number">204</span>, b<span class="tok-operator">:</span> <span class="tok-number">191</span>),
               view<span class="tok-operator">:</span> { <span class="tok-type">AnyView</span>(<span class="tok-function">marker</span>($<span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">rotationEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">30</span>))<span class="tok-operator">.</span><span class="tok-function">offset</span>(x<span class="tok-operator">:</span> <span class="tok-number">160</span>, y<span class="tok-operator">:</span> <span class="tok-number">0</span>)) },
               steps<span class="tok-operator">:</span> [rotate<span class="tok-number">30</span>, <span class="tok-function">shift</span>(<span class="tok-number">160</span>, <span class="tok-number">0</span>)]),
    <span class="tok-type">Experiment</span>(name<span class="tok-operator">:</span> <span class="tok-string">".offset(x: 80), .scaleEffect(2)"</span>, fill<span class="tok-operator">:</span> <span class="tok-type">RGB</span>(r<span class="tok-operator">:</span> <span class="tok-number">245</span>, g<span class="tok-operator">:</span> <span class="tok-number">92</span>, b<span class="tok-operator">:</span> <span class="tok-number">87</span>),
               view<span class="tok-operator">:</span> { <span class="tok-type">AnyView</span>(<span class="tok-function">marker</span>($<span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">offset</span>(x<span class="tok-operator">:</span> <span class="tok-number">80</span>, y<span class="tok-operator">:</span> <span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">scaleEffect</span>(<span class="tok-number">2</span>)) },
               steps<span class="tok-operator">:</span> [<span class="tok-function">shift</span>(<span class="tok-number">80</span>, <span class="tok-number">0</span>), <span class="tok-function">stretch</span>(<span class="tok-number">2</span>, <span class="tok-number">2</span>)]),
    <span class="tok-type">Experiment</span>(name<span class="tok-operator">:</span> <span class="tok-string">".scaleEffect(2), .offset(x: 80)"</span>, fill<span class="tok-operator">:</span> <span class="tok-type">RGB</span>(r<span class="tok-operator">:</span> <span class="tok-number">77</span>, g<span class="tok-operator">:</span> <span class="tok-number">153</span>, b<span class="tok-operator">:</span> <span class="tok-number">250</span>),
               view<span class="tok-operator">:</span> { <span class="tok-type">AnyView</span>(<span class="tok-function">marker</span>($<span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">scaleEffect</span>(<span class="tok-number">2</span>)<span class="tok-operator">.</span><span class="tok-function">offset</span>(x<span class="tok-operator">:</span> <span class="tok-number">80</span>, y<span class="tok-operator">:</span> <span class="tok-number">0</span>)) },
               steps<span class="tok-operator">:</span> [<span class="tok-function">stretch</span>(<span class="tok-number">2</span>, <span class="tok-number">2</span>), <span class="tok-function">shift</span>(<span class="tok-number">80</span>, <span class="tok-number">0</span>)]),
    <span class="tok-type">Experiment</span>(name<span class="tok-operator">:</span> <span class="tok-string">".scaleEffect(x: 2), .rotationEffect(30)"</span>, fill<span class="tok-operator">:</span> <span class="tok-type">RGB</span>(r<span class="tok-operator">:</span> <span class="tok-number">250</span>, g<span class="tok-operator">:</span> <span class="tok-number">219</span>, b<span class="tok-operator">:</span> <span class="tok-number">51</span>),
               view<span class="tok-operator">:</span> { <span class="tok-type">AnyView</span>(<span class="tok-function">marker</span>($<span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">scaleEffect</span>(x<span class="tok-operator">:</span> <span class="tok-number">2</span>, y<span class="tok-operator">:</span> <span class="tok-number">1</span>)<span class="tok-operator">.</span><span class="tok-function">rotationEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">30</span>))) },
               steps<span class="tok-operator">:</span> [<span class="tok-function">stretch</span>(<span class="tok-number">2</span>, <span class="tok-number">1</span>), rotate<span class="tok-number">30</span>]),
    <span class="tok-type">Experiment</span>(name<span class="tok-operator">:</span> <span class="tok-string">".rotationEffect(30), .scaleEffect(x: 2)"</span>, fill<span class="tok-operator">:</span> <span class="tok-type">RGB</span>(r<span class="tok-operator">:</span> <span class="tok-number">140</span>, g<span class="tok-operator">:</span> <span class="tok-number">107</span>, b<span class="tok-operator">:</span> <span class="tok-number">242</span>),
               view<span class="tok-operator">:</span> { <span class="tok-type">AnyView</span>(<span class="tok-function">marker</span>($<span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">rotationEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">30</span>))<span class="tok-operator">.</span><span class="tok-function">scaleEffect</span>(x<span class="tok-operator">:</span> <span class="tok-number">2</span>, y<span class="tok-operator">:</span> <span class="tok-number">1</span>)) },
               steps<span class="tok-operator">:</span> [rotate<span class="tok-number">30</span>, <span class="tok-function">stretch</span>(<span class="tok-number">2</span>, <span class="tok-number">1</span>)]),
    <span class="tok-type">Experiment</span>(name<span class="tok-operator">:</span> <span class="tok-string">".rotationEffect(30, .topLeading), .frame(300 x 200)"</span>, fill<span class="tok-operator">:</span> <span class="tok-type">RGB</span>(r<span class="tok-operator">:</span> <span class="tok-number">89</span>, g<span class="tok-operator">:</span> <span class="tok-number">217</span>, b<span class="tok-operator">:</span> <span class="tok-number">89</span>),
               view<span class="tok-operator">:</span> { <span class="tok-type">AnyView</span>(<span class="tok-function">marker</span>($<span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">rotationEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">30</span>), anchor<span class="tok-operator">:</span> <span class="tok-operator">.</span>top<span class="tok-type">Leading</span>)<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">300</span>, height<span class="tok-operator">:</span> <span class="tok-number">200</span>)) },
               steps<span class="tok-operator">:</span> [<span class="tok-function">about</span>(<span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span> <span class="tok-number">-60</span>, y<span class="tok-operator">:</span> <span class="tok-number">-30</span>), rotate<span class="tok-number">30</span>)]),
    <span class="tok-type">Experiment</span>(name<span class="tok-operator">:</span> <span class="tok-string">".frame(300 x 200), .rotationEffect(30, .topLeading)"</span>, fill<span class="tok-operator">:</span> <span class="tok-type">RGB</span>(r<span class="tok-operator">:</span> <span class="tok-number">230</span>, g<span class="tok-operator">:</span> <span class="tok-number">130</span>, b<span class="tok-operator">:</span> <span class="tok-number">190</span>),
               view<span class="tok-operator">:</span> { <span class="tok-type">AnyView</span>(<span class="tok-function">marker</span>($<span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">300</span>, height<span class="tok-operator">:</span> <span class="tok-number">200</span>)<span class="tok-operator">.</span><span class="tok-function">rotationEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">30</span>), anchor<span class="tok-operator">:</span> <span class="tok-operator">.</span>top<span class="tok-type">Leading</span>)) },
               steps<span class="tok-operator">:</span> [<span class="tok-function">about</span>(<span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span> <span class="tok-number">-150</span>, y<span class="tok-operator">:</span> <span class="tok-number">-100</span>), rotate<span class="tok-number">30</span>)]),
]

<span class="tok-comment">// MARK: rendering</span>

<span class="tok-attribute">@MainActor</span>
<span class="tok-keyword">func</span> <span class="tok-function">renderSwiftUI</span>(_ experiment<span class="tok-operator">:</span> <span class="tok-type">Experiment</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">CGImage</span><span class="tok-operator">?</span> {
    <span class="tok-keyword">let</span> scene <span class="tok-operator">=</span> <span class="tok-type">ZStack</span>(alignment<span class="tok-operator">:</span> <span class="tok-operator">.</span>top<span class="tok-type">Leading</span>) {
        <span class="tok-function">color</span>(background)
        experiment<span class="tok-operator">.</span><span class="tok-function">view</span>(experiment<span class="tok-operator">.</span>fill)<span class="tok-operator">.</span><span class="tok-function">position</span>(x<span class="tok-operator">:</span> center<span class="tok-operator">.</span>x, y<span class="tok-operator">:</span> center<span class="tok-operator">.</span>y)
    }
    <span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> canv<span class="tok-keyword">as</span><span class="tok-operator">.</span>width, height<span class="tok-operator">:</span> canv<span class="tok-keyword">as</span><span class="tok-operator">.</span>height, alignment<span class="tok-operator">:</span> <span class="tok-operator">.</span>top<span class="tok-type">Leading</span>)
    <span class="tok-keyword">let</span> renderer <span class="tok-operator">=</span> <span class="tok-type">ImageRenderer</span>(content<span class="tok-operator">:</span> scene)
    renderer<span class="tok-operator">.</span>scale <span class="tok-operator">=</span> <span class="tok-number">1</span>
    <span class="tok-keyword">return</span> renderer<span class="tok-operator">.</span>cg<span class="tok-type">Image</span>
}

<span class="tok-comment">/// The same transform drawn with Core Graphics in a y-down sRGB bitmap.</span>
<span class="tok-keyword">func</span> <span class="tok-function">renderCoreGraphics</span>(_ experiment<span class="tok-operator">:</span> <span class="tok-type">Experiment</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">CGImage</span><span class="tok-operator">?</span> {
    <span class="tok-keyword">guard</span> <span class="tok-keyword">let</span> context <span class="tok-operator">=</span> <span class="tok-type">CGContext</span>(
        data<span class="tok-operator">:</span> <span class="tok-literal">nil</span>, width<span class="tok-operator">:</span> <span class="tok-type">Int</span>(canv<span class="tok-keyword">as</span><span class="tok-operator">.</span>width), height<span class="tok-operator">:</span> <span class="tok-type">Int</span>(canv<span class="tok-keyword">as</span><span class="tok-operator">.</span>height), bits<span class="tok-type">PerComponent</span><span class="tok-operator">:</span> <span class="tok-number">8</span>, bytes<span class="tok-type">PerRow</span><span class="tok-operator">:</span> <span class="tok-number">0</span>,
        space<span class="tok-operator">:</span> <span class="tok-type">CGColorSpace</span>(name<span class="tok-operator">:</span> <span class="tok-type">CGColorSpace</span><span class="tok-operator">.</span>s<span class="tok-type">RGB</span>)<span class="tok-operator">!</span>, bitmap<span class="tok-type">Info</span><span class="tok-operator">:</span> <span class="tok-type">CGImageAlphaInfo</span><span class="tok-operator">.</span>premultiplied<span class="tok-type">Last</span><span class="tok-operator">.</span>raw<span class="tok-type">Value</span>
    ) <span class="tok-keyword">else</span> { <span class="tok-keyword">return</span> <span class="tok-literal">nil</span> }
    <span class="tok-keyword">func</span> <span class="tok-function">cg</span>(_ c<span class="tok-operator">:</span> <span class="tok-type">RGB</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">CGColor</span> { <span class="tok-type">CGColor</span>(srgb<span class="tok-type">Red</span><span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>(c<span class="tok-operator">.</span>r) <span class="tok-operator">/</span> <span class="tok-number">255</span>, green<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>(c<span class="tok-operator">.</span>g) <span class="tok-operator">/</span> <span class="tok-number">255</span>, blue<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>(c<span class="tok-operator">.</span>b) <span class="tok-operator">/</span> <span class="tok-number">255</span>, alpha<span class="tok-operator">:</span> <span class="tok-number">1</span>) }
    context<span class="tok-operator">.</span><span class="tok-function">translateBy</span>(x<span class="tok-operator">:</span> <span class="tok-number">0</span>, y<span class="tok-operator">:</span> canv<span class="tok-keyword">as</span><span class="tok-operator">.</span>height)
    context<span class="tok-operator">.</span><span class="tok-function">scaleBy</span>(x<span class="tok-operator">:</span> <span class="tok-number">1</span>, y<span class="tok-operator">:</span> <span class="tok-number">-1</span>)
    context<span class="tok-operator">.</span><span class="tok-function">setFillColor</span>(<span class="tok-function">cg</span>(background))
    context<span class="tok-operator">.</span><span class="tok-function">fill</span>(<span class="tok-type">CGRect</span>(orig<span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-operator">.</span>zero, size<span class="tok-operator">:</span> canv<span class="tok-keyword">as</span>))
    context<span class="tok-operator">.</span><span class="tok-function">translateBy</span>(x<span class="tok-operator">:</span> center<span class="tok-operator">.</span>x, y<span class="tok-operator">:</span> center<span class="tok-operator">.</span>y)
    context<span class="tok-operator">.</span><span class="tok-function">concatenate</span>(experiment<span class="tok-operator">.</span>answer)     <span class="tok-comment">// one concatenate: the same matrix, no SwiftUI involved</span>
    context<span class="tok-operator">.</span><span class="tok-function">setFillColor</span>(<span class="tok-function">cg</span>(experiment<span class="tok-operator">.</span>fill))
    context<span class="tok-operator">.</span><span class="tok-function">fill</span>(<span class="tok-type">CGRect</span>(x<span class="tok-operator">:</span> <span class="tok-operator">-</span>marker<span class="tok-type">Size</span><span class="tok-operator">.</span>width <span class="tok-operator">/</span> <span class="tok-number">2</span>, y<span class="tok-operator">:</span> <span class="tok-operator">-</span>marker<span class="tok-type">Size</span><span class="tok-operator">.</span>height <span class="tok-operator">/</span> <span class="tok-number">2</span>, width<span class="tok-operator">:</span> marker<span class="tok-type">Size</span><span class="tok-operator">.</span>width, height<span class="tok-operator">:</span> marker<span class="tok-type">Size</span><span class="tok-operator">.</span>height))
    <span class="tok-keyword">return</span> context<span class="tok-operator">.</span><span class="tok-function">makeImage</span>()
}

<span class="tok-comment">// MARK: measurement</span>

<span class="tok-keyword">func</span> <span class="tok-function">pixels</span>(_ image<span class="tok-operator">:</span> <span class="tok-type">CGImage</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> [<span class="tok-type">UInt8</span>] {
    <span class="tok-keyword">var</span> data <span class="tok-operator">=</span> [<span class="tok-type">UInt8</span>](repeating<span class="tok-operator">:</span> <span class="tok-number">0</span>, count<span class="tok-operator">:</span> image<span class="tok-operator">.</span>width <span class="tok-operator">*</span> image<span class="tok-operator">.</span>height <span class="tok-operator">*</span> <span class="tok-number">4</span>)
    <span class="tok-keyword">let</span> context <span class="tok-operator">=</span> <span class="tok-type">CGContext</span>(
        data<span class="tok-operator">:</span> <span class="tok-operator">&amp;</span>data, width<span class="tok-operator">:</span> image<span class="tok-operator">.</span>width, height<span class="tok-operator">:</span> image<span class="tok-operator">.</span>height, bits<span class="tok-type">PerComponent</span><span class="tok-operator">:</span> <span class="tok-number">8</span>, bytes<span class="tok-type">PerRow</span><span class="tok-operator">:</span> image<span class="tok-operator">.</span>width <span class="tok-operator">*</span> <span class="tok-number">4</span>,
        space<span class="tok-operator">:</span> <span class="tok-type">CGColorSpace</span>(name<span class="tok-operator">:</span> <span class="tok-type">CGColorSpace</span><span class="tok-operator">.</span>s<span class="tok-type">RGB</span>)<span class="tok-operator">!</span>, bitmap<span class="tok-type">Info</span><span class="tok-operator">:</span> <span class="tok-type">CGImageAlphaInfo</span><span class="tok-operator">.</span>premultiplied<span class="tok-type">Last</span><span class="tok-operator">.</span>raw<span class="tok-type">Value</span>
    )<span class="tok-operator">!</span>
    context<span class="tok-operator">.</span><span class="tok-function">draw</span>(image, <span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-type">CGRect</span>(x<span class="tok-operator">:</span> <span class="tok-number">0</span>, y<span class="tok-operator">:</span> <span class="tok-number">0</span>, width<span class="tok-operator">:</span> image<span class="tok-operator">.</span>width, height<span class="tok-operator">:</span> image<span class="tok-operator">.</span>height))
    <span class="tok-keyword">return</span> data
}

<span class="tok-keyword">struct</span> <span class="tok-type">Measured</span> { <span class="tok-keyword">var</span> center<span class="tok-operator">:</span> <span class="tok-type">CGPoint</span>; <span class="tok-keyword">var</span> area<span class="tok-operator">:</span> <span class="tok-type">Double</span>; <span class="tok-keyword">var</span> xx<span class="tok-operator">:</span> <span class="tok-type">Double</span>; <span class="tok-keyword">var</span> xy<span class="tok-operator">:</span> <span class="tok-type">Double</span>; <span class="tok-keyword">var</span> yy<span class="tok-operator">:</span> <span class="tok-type">Double</span> }

<span class="tok-comment">/// Coverage of each pixel = how far its colour lies along the line background -&gt; marker.</span>
<span class="tok-comment">/// Pixel (i, j) is the square [i, i+1] x [j, j+1], so its centre is (i + 0.5, j + 0.5).</span>
<span class="tok-keyword">func</span> <span class="tok-function">measure</span>(_ image<span class="tok-operator">:</span> <span class="tok-type">CGImage</span>, fill<span class="tok-operator">:</span> <span class="tok-type">RGB</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Measured</span><span class="tok-operator">?</span> {
    <span class="tok-keyword">let</span> data <span class="tok-operator">=</span> <span class="tok-function">pixels</span>(image)
    <span class="tok-keyword">let</span> bg <span class="tok-operator">=</span> [<span class="tok-type">Double</span>(background<span class="tok-operator">.</span>r), <span class="tok-type">Double</span>(background<span class="tok-operator">.</span>g), <span class="tok-type">Double</span>(background<span class="tok-operator">.</span>b)]
    <span class="tok-keyword">let</span> ax<span class="tok-keyword">is</span> <span class="tok-operator">=</span> [<span class="tok-type">Double</span>(fill<span class="tok-operator">.</span>r) <span class="tok-operator">-</span> bg[<span class="tok-number">0</span>], <span class="tok-type">Double</span>(fill<span class="tok-operator">.</span>g) <span class="tok-operator">-</span> bg[<span class="tok-number">1</span>], <span class="tok-type">Double</span>(fill<span class="tok-operator">.</span>b) <span class="tok-operator">-</span> bg[<span class="tok-number">2</span>]]
    <span class="tok-keyword">let</span> axis<span class="tok-type">LengthSquared</span> <span class="tok-operator">=</span> ax<span class="tok-keyword">is</span><span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-number">0</span>) { $<span class="tok-number">0</span> <span class="tok-operator">+</span> $<span class="tok-number">1</span> <span class="tok-operator">*</span> $<span class="tok-number">1</span> }
    <span class="tok-keyword">var</span> samples<span class="tok-operator">:</span> [(w<span class="tok-operator">:</span> <span class="tok-type">Double</span>, x<span class="tok-operator">:</span> <span class="tok-type">Double</span>, y<span class="tok-operator">:</span> <span class="tok-type">Double</span>)] <span class="tok-operator">=</span> []
    <span class="tok-keyword">for</span> row <span class="tok-keyword">in</span> <span class="tok-number">0</span> <span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">&lt;</span> image<span class="tok-operator">.</span>height {
        <span class="tok-keyword">for</span> column <span class="tok-keyword">in</span> <span class="tok-number">0</span> <span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">&lt;</span> image<span class="tok-operator">.</span>width {
            <span class="tok-keyword">let</span> o <span class="tok-operator">=</span> (row <span class="tok-operator">*</span> image<span class="tok-operator">.</span>width <span class="tok-operator">+</span> column) <span class="tok-operator">*</span> <span class="tok-number">4</span>
            <span class="tok-keyword">let</span> delta <span class="tok-operator">=</span> [<span class="tok-type">Double</span>(data[o]) <span class="tok-operator">-</span> bg[<span class="tok-number">0</span>], <span class="tok-type">Double</span>(data[o <span class="tok-operator">+</span> <span class="tok-number">1</span>]) <span class="tok-operator">-</span> bg[<span class="tok-number">1</span>], <span class="tok-type">Double</span>(data[o <span class="tok-operator">+</span> <span class="tok-number">2</span>]) <span class="tok-operator">-</span> bg[<span class="tok-number">2</span>]]
            <span class="tok-keyword">let</span> w <span class="tok-operator">=</span> <span class="tok-function">min</span>(<span class="tok-number">1</span>, <span class="tok-function">max</span>(<span class="tok-number">0</span>, <span class="tok-function">zip</span>(delta, ax<span class="tok-keyword">is</span>)<span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-number">0</span>) { $<span class="tok-number">0</span> <span class="tok-operator">+</span> $<span class="tok-number">1.0</span> <span class="tok-operator">*</span> $<span class="tok-number">1.1</span> } <span class="tok-operator">/</span> axis<span class="tok-type">LengthSquared</span>))
            <span class="tok-keyword">let</span> residual <span class="tok-operator">=</span> <span class="tok-function">zip</span>(delta, ax<span class="tok-keyword">is</span>)<span class="tok-operator">.</span>map { $<span class="tok-number">0</span> <span class="tok-operator">-</span> w <span class="tok-operator">*</span> $<span class="tok-number">1</span> }<span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-number">0</span>) { $<span class="tok-number">0</span> <span class="tok-operator">+</span> $<span class="tok-number">1</span> <span class="tok-operator">*</span> $<span class="tok-number">1</span> }<span class="tok-operator">.</span><span class="tok-function">squareRoot</span>()
            <span class="tok-keyword">if</span> w <span class="tok-operator">&gt;</span> <span class="tok-number">0</span>, residual <span class="tok-operator">&lt;</span><span class="tok-operator">=</span> <span class="tok-number">12</span> { samples<span class="tok-operator">.</span><span class="tok-function">append</span>((w, <span class="tok-type">Double</span>(column) <span class="tok-operator">+</span> <span class="tok-number">0.5</span>, <span class="tok-type">Double</span>(row) <span class="tok-operator">+</span> <span class="tok-number">0.5</span>)) }
        }
    }
    <span class="tok-keyword">let</span> total <span class="tok-operator">=</span> samples<span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-number">0</span>) { $<span class="tok-number">0</span> <span class="tok-operator">+</span> $<span class="tok-number">1.</span>w }
    <span class="tok-keyword">guard</span> total <span class="tok-operator">&gt;</span> <span class="tok-number">0</span> <span class="tok-keyword">else</span> { <span class="tok-keyword">return</span> <span class="tok-literal">nil</span> }
    <span class="tok-keyword">let</span> cx <span class="tok-operator">=</span> samples<span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-number">0</span>) { $<span class="tok-number">0</span> <span class="tok-operator">+</span> $<span class="tok-number">1.</span>w <span class="tok-operator">*</span> $<span class="tok-number">1.</span>x } <span class="tok-operator">/</span> total
    <span class="tok-keyword">let</span> cy <span class="tok-operator">=</span> samples<span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-number">0</span>) { $<span class="tok-number">0</span> <span class="tok-operator">+</span> $<span class="tok-number">1.</span>w <span class="tok-operator">*</span> $<span class="tok-number">1.</span>y } <span class="tok-operator">/</span> total
    <span class="tok-keyword">let</span> xx <span class="tok-operator">=</span> samples<span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-number">0</span>) { $<span class="tok-number">0</span> <span class="tok-operator">+</span> $<span class="tok-number">1.</span>w <span class="tok-operator">*</span> ($<span class="tok-number">1.</span>x <span class="tok-operator">-</span> cx) <span class="tok-operator">*</span> ($<span class="tok-number">1.</span>x <span class="tok-operator">-</span> cx) } <span class="tok-operator">/</span> total <span class="tok-operator">+</span> <span class="tok-number">1.0</span> <span class="tok-operator">/</span> <span class="tok-number">12</span>
    <span class="tok-keyword">let</span> xy <span class="tok-operator">=</span> samples<span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-number">0</span>) { $<span class="tok-number">0</span> <span class="tok-operator">+</span> $<span class="tok-number">1.</span>w <span class="tok-operator">*</span> ($<span class="tok-number">1.</span>x <span class="tok-operator">-</span> cx) <span class="tok-operator">*</span> ($<span class="tok-number">1.</span>y <span class="tok-operator">-</span> cy) } <span class="tok-operator">/</span> total
    <span class="tok-keyword">let</span> yy <span class="tok-operator">=</span> samples<span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-number">0</span>) { $<span class="tok-number">0</span> <span class="tok-operator">+</span> $<span class="tok-number">1.</span>w <span class="tok-operator">*</span> ($<span class="tok-number">1.</span>y <span class="tok-operator">-</span> cy) <span class="tok-operator">*</span> ($<span class="tok-number">1.</span>y <span class="tok-operator">-</span> cy) } <span class="tok-operator">/</span> total <span class="tok-operator">+</span> <span class="tok-number">1.0</span> <span class="tok-operator">/</span> <span class="tok-number">12</span>
    <span class="tok-keyword">return</span> <span class="tok-type">Measured</span>(center<span class="tok-operator">:</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span> cx, y<span class="tok-operator">:</span> cy), area<span class="tok-operator">:</span> total, xx<span class="tok-operator">:</span> xx, xy<span class="tok-operator">:</span> xy, yy<span class="tok-operator">:</span> yy)
}

<span class="tok-comment">/// Closed-form prediction: where the centre goes, how much area, and the second moments.</span>
<span class="tok-keyword">func</span> <span class="tok-function">predict</span>(_ t<span class="tok-operator">:</span> <span class="tok-type">CGAffineTransform</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Measured</span> {
    <span class="tok-keyword">let</span> c <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span> center<span class="tok-operator">.</span>x <span class="tok-operator">+</span> t<span class="tok-operator">.</span>tx, y<span class="tok-operator">:</span> center<span class="tok-operator">.</span>y <span class="tok-operator">+</span> t<span class="tok-operator">.</span>ty)
    <span class="tok-keyword">let</span> sx <span class="tok-operator">=</span> <span class="tok-type">Double</span>(marker<span class="tok-type">Size</span><span class="tok-operator">.</span>width <span class="tok-operator">*</span> marker<span class="tok-type">Size</span><span class="tok-operator">.</span>width) <span class="tok-operator">/</span> <span class="tok-number">12</span>, sy <span class="tok-operator">=</span> <span class="tok-type">Double</span>(marker<span class="tok-type">Size</span><span class="tok-operator">.</span>height <span class="tok-operator">*</span> marker<span class="tok-type">Size</span><span class="tok-operator">.</span>height) <span class="tok-operator">/</span> <span class="tok-number">12</span>
    <span class="tok-keyword">let</span> a <span class="tok-operator">=</span> <span class="tok-type">Double</span>(t<span class="tok-operator">.</span>a), b <span class="tok-operator">=</span> <span class="tok-type">Double</span>(t<span class="tok-operator">.</span>b), cc <span class="tok-operator">=</span> <span class="tok-type">Double</span>(t<span class="tok-operator">.</span>c), d <span class="tok-operator">=</span> <span class="tok-type">Double</span>(t<span class="tok-operator">.</span>d)
    <span class="tok-keyword">return</span> <span class="tok-type">Measured</span>(
        center<span class="tok-operator">:</span> c, area<span class="tok-operator">:</span> <span class="tok-type">Double</span>(marker<span class="tok-type">Size</span><span class="tok-operator">.</span>width <span class="tok-operator">*</span> marker<span class="tok-type">Size</span><span class="tok-operator">.</span>height) <span class="tok-operator">*</span> <span class="tok-function">abs</span>(a <span class="tok-operator">*</span> d <span class="tok-operator">-</span> b <span class="tok-operator">*</span> cc),
        xx<span class="tok-operator">:</span> a <span class="tok-operator">*</span> a <span class="tok-operator">*</span> sx <span class="tok-operator">+</span> cc <span class="tok-operator">*</span> cc <span class="tok-operator">*</span> sy, xy<span class="tok-operator">:</span> a <span class="tok-operator">*</span> b <span class="tok-operator">*</span> sx <span class="tok-operator">+</span> cc <span class="tok-operator">*</span> d <span class="tok-operator">*</span> sy, yy<span class="tok-operator">:</span> b <span class="tok-operator">*</span> b <span class="tok-operator">*</span> sx <span class="tok-operator">+</span> d <span class="tok-operator">*</span> d <span class="tok-operator">*</span> sy
    )
}

<span class="tok-comment">// MARK: report</span>

<span class="tok-attribute">@MainActor</span>
<span class="tok-keyword">func</span> <span class="tok-function">run</span>() {
    <span class="tok-function">print</span>(<span class="tok-string">"chain                                                   predicted        measured         err px  shape err  swapped partner would miss by      swiftui vs CG twin"</span>)
    <span class="tok-keyword">var</span> worst <span class="tok-operator">=</span> <span class="tok-number">0.0</span>, worst<span class="tok-type">Shape</span> <span class="tok-operator">=</span> <span class="tok-number">0.0</span>
    <span class="tok-keyword">for</span> (index, experiment) <span class="tok-keyword">in</span> experiments<span class="tok-operator">.</span><span class="tok-function">enumerated</span>() {
        <span class="tok-keyword">guard</span> <span class="tok-keyword">let</span> image <span class="tok-operator">=</span> <span class="tok-function">renderSwiftUI</span>(experiment), <span class="tok-keyword">let</span> m <span class="tok-operator">=</span> <span class="tok-function">measure</span>(image, fill<span class="tok-operator">:</span> experiment<span class="tok-operator">.</span>fill) <span class="tok-keyword">else</span> {
            <span class="tok-function">print</span>(<span class="tok-string">"\(experiment.name): render or measurement failed"</span>); <span class="tok-keyword">continue</span>
        }
        <span class="tok-comment">// The matrix is expressed about the marker's own centre, so the centre ends up (tx, ty) from where it started.</span>
        <span class="tok-keyword">let</span> p <span class="tok-operator">=</span> <span class="tok-function">predict</span>(experiment<span class="tok-operator">.</span>answer)
        <span class="tok-keyword">let</span> error <span class="tok-operator">=</span> <span class="tok-function">hypot</span>(m<span class="tok-operator">.</span>center<span class="tok-operator">.</span>x <span class="tok-operator">-</span> p<span class="tok-operator">.</span>center<span class="tok-operator">.</span>x, m<span class="tok-operator">.</span>center<span class="tok-operator">.</span>y <span class="tok-operator">-</span> p<span class="tok-operator">.</span>center<span class="tok-operator">.</span>y)
        <span class="tok-comment">// Control: the partner is the same two modifiers written in the other order.</span>
        <span class="tok-comment">// If the measurement could not tell the two orders apart, it would prove nothing.</span>
        <span class="tok-keyword">let</span> q <span class="tok-operator">=</span> <span class="tok-function">predict</span>(experiments[index <span class="tok-operator">^</span> <span class="tok-number">1</span>]<span class="tok-operator">.</span>answer)
        <span class="tok-keyword">let</span> centre<span class="tok-type">Miss</span> <span class="tok-operator">=</span> <span class="tok-function">hypot</span>(m<span class="tok-operator">.</span>center<span class="tok-operator">.</span>x <span class="tok-operator">-</span> q<span class="tok-operator">.</span>center<span class="tok-operator">.</span>x, m<span class="tok-operator">.</span>center<span class="tok-operator">.</span>y <span class="tok-operator">-</span> q<span class="tok-operator">.</span>center<span class="tok-operator">.</span>y)
        <span class="tok-keyword">let</span> scale <span class="tok-operator">=</span> <span class="tok-function">max</span>(p<span class="tok-operator">.</span>xx, p<span class="tok-operator">.</span>yy)
        <span class="tok-keyword">func</span> <span class="tok-function">shapeError</span>(_ x<span class="tok-operator">:</span> <span class="tok-type">Measured</span>, _ y<span class="tok-operator">:</span> <span class="tok-type">Measured</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Double</span> {
            <span class="tok-function">max</span>(<span class="tok-function">abs</span>(x<span class="tok-operator">.</span>xx <span class="tok-operator">-</span> y<span class="tok-operator">.</span>xx), <span class="tok-function">abs</span>(x<span class="tok-operator">.</span>xy <span class="tok-operator">-</span> y<span class="tok-operator">.</span>xy), <span class="tok-function">abs</span>(x<span class="tok-operator">.</span>yy <span class="tok-operator">-</span> y<span class="tok-operator">.</span>yy)) <span class="tok-operator">/</span> scale
        }
        <span class="tok-keyword">let</span> own<span class="tok-type">Shape</span> <span class="tok-operator">=</span> <span class="tok-function">shapeError</span>(m, p), partner<span class="tok-type">Shape</span> <span class="tok-operator">=</span> <span class="tok-function">shapeError</span>(m, q)
        <span class="tok-keyword">let</span> swapped <span class="tok-operator">=</span> <span class="tok-type">String</span>(format<span class="tok-operator">:</span> <span class="tok-string">"centre %.1f px, shape %.1f%%"</span>, centre<span class="tok-type">Miss</span>, <span class="tok-number">100</span> <span class="tok-operator">*</span> partner<span class="tok-type">Shape</span>)
        worst <span class="tok-operator">=</span> <span class="tok-function">max</span>(worst, error)
        worst<span class="tok-type">Shape</span> <span class="tok-operator">=</span> <span class="tok-function">max</span>(worst<span class="tok-type">Shape</span>, own<span class="tok-type">Shape</span>)
        <span class="tok-keyword">var</span> tw<span class="tok-keyword">in</span> <span class="tok-operator">=</span> <span class="tok-string">"n/a"</span>
        <span class="tok-keyword">if</span> <span class="tok-keyword">let</span> cg<span class="tok-type">Image</span> <span class="tok-operator">=</span> <span class="tok-function">renderCoreGraphics</span>(experiment) {
            <span class="tok-keyword">let</span> a <span class="tok-operator">=</span> <span class="tok-function">pixels</span>(image), b <span class="tok-operator">=</span> <span class="tok-function">pixels</span>(cg<span class="tok-type">Image</span>)
            <span class="tok-keyword">let</span> differing <span class="tok-operator">=</span> <span class="tok-function">stride</span>(from<span class="tok-operator">:</span> <span class="tok-number">0</span>, to<span class="tok-operator">:</span> a<span class="tok-operator">.</span>count, by<span class="tok-operator">:</span> <span class="tok-number">4</span>)<span class="tok-operator">.</span>filter { a[$<span class="tok-number">0</span> <span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">&lt;</span> $<span class="tok-number">0</span> <span class="tok-operator">+</span> <span class="tok-number">4</span>] <span class="tok-operator">!</span><span class="tok-operator">=</span> b[$<span class="tok-number">0</span> <span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">&lt;</span> $<span class="tok-number">0</span> <span class="tok-operator">+</span> <span class="tok-number">4</span>] }<span class="tok-operator">.</span>count
            <span class="tok-keyword">let</span> total <span class="tok-operator">=</span> <span class="tok-function">zip</span>(a, b)<span class="tok-operator">.</span><span class="tok-function">reduce</span>(<span class="tok-number">0</span>) { $<span class="tok-number">0</span> <span class="tok-operator">+</span> <span class="tok-function">abs</span>(<span class="tok-type">Int</span>($<span class="tok-number">1.0</span>) <span class="tok-operator">-</span> <span class="tok-type">Int</span>($<span class="tok-number">1.1</span>)) }
            tw<span class="tok-keyword">in</span> <span class="tok-operator">=</span> <span class="tok-type">String</span>(format<span class="tok-operator">:</span> <span class="tok-string">"%d px differ, mean %.4f%%"</span>, differing, <span class="tok-number">100</span> <span class="tok-operator">*</span> <span class="tok-type">Double</span>(total) <span class="tok-operator">/</span> (<span class="tok-type">Double</span>(a<span class="tok-operator">.</span>count) <span class="tok-operator">*</span> <span class="tok-number">255</span>))
        }
        <span class="tok-function">print</span>(<span class="tok-type">String</span>(format<span class="tok-operator">:</span> <span class="tok-string">"%@ (%.1f, %.1f)  (%.1f, %.1f)  %.3f  %.4f%%    %@  %@"</span>,
                     experiment<span class="tok-operator">.</span>name<span class="tok-operator">.</span><span class="tok-function">padding</span>(to<span class="tok-type">Length</span><span class="tok-operator">:</span> <span class="tok-number">54</span>, with<span class="tok-type">Pad</span><span class="tok-operator">:</span> <span class="tok-string">" "</span>, starting<span class="tok-type">At</span><span class="tok-operator">:</span> <span class="tok-number">0</span>),
                     p<span class="tok-operator">.</span>center<span class="tok-operator">.</span>x, p<span class="tok-operator">.</span>center<span class="tok-operator">.</span>y, m<span class="tok-operator">.</span>center<span class="tok-operator">.</span>x, m<span class="tok-operator">.</span>center<span class="tok-operator">.</span>y, error, <span class="tok-number">100</span> <span class="tok-operator">*</span> own<span class="tok-type">Shape</span>,
                     swapped<span class="tok-operator">.</span><span class="tok-function">padding</span>(to<span class="tok-type">Length</span><span class="tok-operator">:</span> <span class="tok-number">32</span>, with<span class="tok-type">Pad</span><span class="tok-operator">:</span> <span class="tok-string">" "</span>, starting<span class="tok-type">At</span><span class="tok-operator">:</span> <span class="tok-number">0</span>), tw<span class="tok-keyword">in</span>))
    }
    <span class="tok-function">print</span>(<span class="tok-type">String</span>(format<span class="tok-operator">:</span> <span class="tok-string">"worst centre error: %.4f px, worst shape error: %.4f%% of the larger variance"</span>, worst, <span class="tok-number">100</span> <span class="tok-operator">*</span> worst<span class="tok-type">Shape</span>))
}

<span class="tok-type">MainActor</span><span class="tok-operator">.</span>assume<span class="tok-keyword">Isolated</span> { <span class="tok-function">run</span>() }</code></pre>
<p>The snapping witness, 62 lines, prints both rounding tables:</p>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">AppKit</span>
<span class="tok-keyword">import</span> <span class="tok-type">SwiftUI</span>

<span class="tok-comment">// Witness: where does SwiftUI actually put a view you offset by a fractional amount?</span>
<span class="tok-comment">// A 120 x 60 orange marker is laid out with its centre at x = 400, offset, rendered</span>
<span class="tok-comment">// with ImageRenderer at a chosen scale, and its centre of coverage is measured.</span>

<span class="tok-keyword">let</span> background <span class="tok-operator">=</span> (r<span class="tok-operator">:</span> <span class="tok-number">14.0</span>, g<span class="tok-operator">:</span> <span class="tok-number">16.0</span>, b<span class="tok-operator">:</span> <span class="tok-number">24.0</span>)
<span class="tok-keyword">let</span> orange <span class="tok-operator">=</span> (r<span class="tok-operator">:</span> <span class="tok-number">250.0</span>, g<span class="tok-operator">:</span> <span class="tok-number">140.0</span>, b<span class="tok-operator">:</span> <span class="tok-number">31.0</span>)

<span class="tok-attribute">@MainActor</span>
<span class="tok-keyword">func</span> measured<span class="tok-type">CentreX</span><span class="tok-operator">&lt;</span><span class="tok-type">V</span><span class="tok-operator">:</span> <span class="tok-type">View</span><span class="tok-operator">&gt;</span>(_ marker<span class="tok-operator">:</span> <span class="tok-type">V</span>, render<span class="tok-type">Scale</span><span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Double</span> {
    <span class="tok-keyword">let</span> scene <span class="tok-operator">=</span> <span class="tok-type">ZStack</span>(alignment<span class="tok-operator">:</span> <span class="tok-operator">.</span>top<span class="tok-type">Leading</span>) {
        <span class="tok-type">Color</span>(red<span class="tok-operator">:</span> background<span class="tok-operator">.</span>r <span class="tok-operator">/</span> <span class="tok-number">255</span>, green<span class="tok-operator">:</span> background<span class="tok-operator">.</span>g <span class="tok-operator">/</span> <span class="tok-number">255</span>, blue<span class="tok-operator">:</span> background<span class="tok-operator">.</span>b <span class="tok-operator">/</span> <span class="tok-number">255</span>)
        marker<span class="tok-operator">.</span><span class="tok-function">position</span>(x<span class="tok-operator">:</span> <span class="tok-number">400</span>, y<span class="tok-operator">:</span> <span class="tok-number">225</span>)
    }
    <span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">800</span>, height<span class="tok-operator">:</span> <span class="tok-number">450</span>, alignment<span class="tok-operator">:</span> <span class="tok-operator">.</span>top<span class="tok-type">Leading</span>)
    <span class="tok-keyword">let</span> renderer <span class="tok-operator">=</span> <span class="tok-type">ImageRenderer</span>(content<span class="tok-operator">:</span> scene)
    renderer<span class="tok-operator">.</span>scale <span class="tok-operator">=</span> render<span class="tok-type">Scale</span>
    <span class="tok-keyword">let</span> image <span class="tok-operator">=</span> renderer<span class="tok-operator">.</span>cg<span class="tok-type">Image</span><span class="tok-operator">!</span>
    <span class="tok-keyword">var</span> data <span class="tok-operator">=</span> [<span class="tok-type">UInt8</span>](repeating<span class="tok-operator">:</span> <span class="tok-number">0</span>, count<span class="tok-operator">:</span> image<span class="tok-operator">.</span>width <span class="tok-operator">*</span> image<span class="tok-operator">.</span>height <span class="tok-operator">*</span> <span class="tok-number">4</span>)
    <span class="tok-keyword">let</span> context <span class="tok-operator">=</span> <span class="tok-type">CGContext</span>(
        data<span class="tok-operator">:</span> <span class="tok-operator">&amp;</span>data, width<span class="tok-operator">:</span> image<span class="tok-operator">.</span>width, height<span class="tok-operator">:</span> image<span class="tok-operator">.</span>height, bits<span class="tok-type">PerComponent</span><span class="tok-operator">:</span> <span class="tok-number">8</span>, bytes<span class="tok-type">PerRow</span><span class="tok-operator">:</span> image<span class="tok-operator">.</span>width <span class="tok-operator">*</span> <span class="tok-number">4</span>,
        space<span class="tok-operator">:</span> <span class="tok-type">CGColorSpace</span>(name<span class="tok-operator">:</span> <span class="tok-type">CGColorSpace</span><span class="tok-operator">.</span>s<span class="tok-type">RGB</span>)<span class="tok-operator">!</span>, bitmap<span class="tok-type">Info</span><span class="tok-operator">:</span> <span class="tok-type">CGImageAlphaInfo</span><span class="tok-operator">.</span>premultiplied<span class="tok-type">Last</span><span class="tok-operator">.</span>raw<span class="tok-type">Value</span>
    )<span class="tok-operator">!</span>
    context<span class="tok-operator">.</span><span class="tok-function">draw</span>(image, <span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-type">CGRect</span>(x<span class="tok-operator">:</span> <span class="tok-number">0</span>, y<span class="tok-operator">:</span> <span class="tok-number">0</span>, width<span class="tok-operator">:</span> image<span class="tok-operator">.</span>width, height<span class="tok-operator">:</span> image<span class="tok-operator">.</span>height))
    <span class="tok-keyword">let</span> ax<span class="tok-keyword">is</span> <span class="tok-operator">=</span> (orange<span class="tok-operator">.</span>r <span class="tok-operator">-</span> background<span class="tok-operator">.</span>r, orange<span class="tok-operator">.</span>g <span class="tok-operator">-</span> background<span class="tok-operator">.</span>g, orange<span class="tok-operator">.</span>b <span class="tok-operator">-</span> background<span class="tok-operator">.</span>b)
    <span class="tok-keyword">let</span> axis<span class="tok-type">LengthSquared</span> <span class="tok-operator">=</span> ax<span class="tok-keyword">is</span><span class="tok-operator">.</span><span class="tok-number">0</span> <span class="tok-operator">*</span> ax<span class="tok-keyword">is</span><span class="tok-operator">.</span><span class="tok-number">0</span> <span class="tok-operator">+</span> ax<span class="tok-keyword">is</span><span class="tok-operator">.</span><span class="tok-number">1</span> <span class="tok-operator">*</span> ax<span class="tok-keyword">is</span><span class="tok-operator">.</span><span class="tok-number">1</span> <span class="tok-operator">+</span> ax<span class="tok-keyword">is</span><span class="tok-operator">.</span><span class="tok-number">2</span> <span class="tok-operator">*</span> ax<span class="tok-keyword">is</span><span class="tok-operator">.</span><span class="tok-number">2</span>
    <span class="tok-keyword">var</span> total <span class="tok-operator">=</span> <span class="tok-number">0.0</span>, moment <span class="tok-operator">=</span> <span class="tok-number">0.0</span>
    <span class="tok-keyword">for</span> row <span class="tok-keyword">in</span> <span class="tok-number">0</span> <span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">&lt;</span> image<span class="tok-operator">.</span>height {
        <span class="tok-keyword">for</span> column <span class="tok-keyword">in</span> <span class="tok-number">0</span> <span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">&lt;</span> image<span class="tok-operator">.</span>width {
            <span class="tok-keyword">let</span> o <span class="tok-operator">=</span> (row <span class="tok-operator">*</span> image<span class="tok-operator">.</span>width <span class="tok-operator">+</span> column) <span class="tok-operator">*</span> <span class="tok-number">4</span>
            <span class="tok-keyword">let</span> d <span class="tok-operator">=</span> (<span class="tok-type">Double</span>(data[o]) <span class="tok-operator">-</span> background<span class="tok-operator">.</span>r, <span class="tok-type">Double</span>(data[o <span class="tok-operator">+</span> <span class="tok-number">1</span>]) <span class="tok-operator">-</span> background<span class="tok-operator">.</span>g, <span class="tok-type">Double</span>(data[o <span class="tok-operator">+</span> <span class="tok-number">2</span>]) <span class="tok-operator">-</span> background<span class="tok-operator">.</span>b)
            <span class="tok-keyword">let</span> w <span class="tok-operator">=</span> <span class="tok-function">min</span>(<span class="tok-number">1</span>, <span class="tok-function">max</span>(<span class="tok-number">0</span>, (d<span class="tok-operator">.</span><span class="tok-number">0</span> <span class="tok-operator">*</span> ax<span class="tok-keyword">is</span><span class="tok-operator">.</span><span class="tok-number">0</span> <span class="tok-operator">+</span> d<span class="tok-operator">.</span><span class="tok-number">1</span> <span class="tok-operator">*</span> ax<span class="tok-keyword">is</span><span class="tok-operator">.</span><span class="tok-number">1</span> <span class="tok-operator">+</span> d<span class="tok-operator">.</span><span class="tok-number">2</span> <span class="tok-operator">*</span> ax<span class="tok-keyword">is</span><span class="tok-operator">.</span><span class="tok-number">2</span>) <span class="tok-operator">/</span> axis<span class="tok-type">LengthSquared</span>))
            total <span class="tok-operator">+</span><span class="tok-operator">=</span> w
            moment <span class="tok-operator">+</span><span class="tok-operator">=</span> w <span class="tok-operator">*</span> (<span class="tok-type">Double</span>(column) <span class="tok-operator">+</span> <span class="tok-number">0.5</span>)
        }
    }
    <span class="tok-keyword">return</span> moment <span class="tok-operator">/</span> total <span class="tok-operator">/</span> <span class="tok-type">Double</span>(render<span class="tok-type">Scale</span>)    <span class="tok-comment">// back to points</span>
}

<span class="tok-attribute">@MainActor</span>
<span class="tok-keyword">func</span> <span class="tok-function">run</span>() {
    <span class="tok-keyword">func</span> <span class="tok-function">marker</span>() <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-keyword">some</span> <span class="tok-type">View</span> { <span class="tok-type">Rectangle</span>()<span class="tok-operator">.</span><span class="tok-function">fill</span>(<span class="tok-type">Color</span>(red<span class="tok-operator">:</span> orange<span class="tok-operator">.</span>r <span class="tok-operator">/</span> <span class="tok-number">255</span>, green<span class="tok-operator">:</span> orange<span class="tok-operator">.</span>g <span class="tok-operator">/</span> <span class="tok-number">255</span>, blue<span class="tok-operator">:</span> orange<span class="tok-operator">.</span>b <span class="tok-operator">/</span> <span class="tok-number">255</span>))<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">120</span>, height<span class="tok-operator">:</span> <span class="tok-number">60</span>) }

    <span class="tok-function">print</span>(<span class="tok-string">".offset(x:) alone, centre moved by (points):"</span>)
    <span class="tok-function">print</span>(<span class="tok-string">"requested   scale 1   scale 2   scale 3"</span>)
    <span class="tok-keyword">for</span> t <span class="tok-keyword">in</span> [<span class="tok-number">-10.5</span>, <span class="tok-number">-0.6</span>, <span class="tok-number">-0.5</span>, <span class="tok-number">-0.4</span>, <span class="tok-number">0.2</span>, <span class="tok-number">0.25</span>, <span class="tok-number">0.3</span>, <span class="tok-number">0.5</span>, <span class="tok-number">0.74</span>, <span class="tok-number">0.75</span>, <span class="tok-number">10.3</span>, <span class="tok-number">10.5</span>] {
        <span class="tok-keyword">let</span> row <span class="tok-operator">=</span> [<span class="tok-number">1</span>, <span class="tok-number">2</span>, <span class="tok-number">3</span>]<span class="tok-operator">.</span>map { <span class="tok-function">measuredCentreX</span>(<span class="tok-function">marker</span>()<span class="tok-operator">.</span><span class="tok-function">offset</span>(x<span class="tok-operator">:</span> t, y<span class="tok-operator">:</span> <span class="tok-number">0</span>), render<span class="tok-type">Scale</span><span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>($<span class="tok-number">0</span>)) <span class="tok-operator">-</span> <span class="tok-number">400</span> }
        <span class="tok-function">print</span>(<span class="tok-type">String</span>(format<span class="tok-operator">:</span> <span class="tok-string">"%8.2f  %8.3f  %8.3f  %8.3f"</span>, t, row[<span class="tok-number">0</span>], row[<span class="tok-number">1</span>], row[<span class="tok-number">2</span>]))
    }

    <span class="tok-function">print</span>(<span class="tok-string">"\nThen a scale of 2 after it, at render scale 1 (centre moved by, points):"</span>)
    <span class="tok-function">print</span>(<span class="tok-string">"requested   .offset, .scaleEffect(2)   algebra says   .scaleEffect(2), .offset   algebra says"</span>)
    <span class="tok-keyword">for</span> t <span class="tok-keyword">in</span> [<span class="tok-number">0.0</span>, <span class="tok-number">0.25</span>, <span class="tok-number">0.5</span>, <span class="tok-number">0.75</span>, <span class="tok-number">10.3</span>, <span class="tok-number">10.5</span>, <span class="tok-number">79.6</span>] {
        <span class="tok-keyword">let</span> first <span class="tok-operator">=</span> <span class="tok-function">measuredCentreX</span>(<span class="tok-function">marker</span>()<span class="tok-operator">.</span><span class="tok-function">offset</span>(x<span class="tok-operator">:</span> t, y<span class="tok-operator">:</span> <span class="tok-number">0</span>)<span class="tok-operator">.</span><span class="tok-function">scaleEffect</span>(<span class="tok-number">2</span>), render<span class="tok-type">Scale</span><span class="tok-operator">:</span> <span class="tok-number">1</span>) <span class="tok-operator">-</span> <span class="tok-number">400</span>
        <span class="tok-keyword">let</span> second <span class="tok-operator">=</span> <span class="tok-function">measuredCentreX</span>(<span class="tok-function">marker</span>()<span class="tok-operator">.</span><span class="tok-function">scaleEffect</span>(<span class="tok-number">2</span>)<span class="tok-operator">.</span><span class="tok-function">offset</span>(x<span class="tok-operator">:</span> t, y<span class="tok-operator">:</span> <span class="tok-number">0</span>), render<span class="tok-type">Scale</span><span class="tok-operator">:</span> <span class="tok-number">1</span>) <span class="tok-operator">-</span> <span class="tok-number">400</span>
        <span class="tok-function">print</span>(<span class="tok-type">String</span>(format<span class="tok-operator">:</span> <span class="tok-string">"%8.2f  %24.3f  %13.2f  %24.3f  %13.2f"</span>, t, first, <span class="tok-number">2</span> <span class="tok-operator">*</span> t, second, t))
    }
}

<span class="tok-type">MainActor</span><span class="tok-operator">.</span>assume<span class="tok-keyword">Isolated</span> { <span class="tok-function">run</span>() }</code></pre>
<p>The full output of the snapping program on the machine that produced this post has more rows than the tables above, and every row agrees with the rule stated there: the amount is rounded to a multiple of one over the render scale, with ties going up.</p>
<p>The Core Graphics half of this story, drawn twice and measured the same way across six figures and three 72-frame animations, is <a href="https://appleuiinsider.com/issues/order-matters/">Apple UI Insider Issue 2</a>. In <a href="https://aleahim.com/blog/the-swiftui-oracle/">The SwiftUI Oracle</a> I argued that SwiftUI’s behaviour should be checked against an answer key, not trusted from the way it looks. This is one more instance. The folklore about modifier order turns out to be a matrix product, read from the other end, with one rounding rule that no amount of staring at the picture would have shown me.</p>]]></content:encoded>
</item>
<item>
<title>Introducing Apple UI Insider</title>
<link>https://aleahim.com/blog/apple-ui-insider/</link>
<guid isPermaLink="true">https://aleahim.com/blog/apple-ui-insider/</guid>
<pubDate>Sat, 01 Aug 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>A new newsletter that draws every picture twice, once with a clean-room renderer, once with Apple&apos;s own frameworks, and publishes what&apos;s different</description>
<content:encoded><![CDATA[<h1>Introducing Apple UI Insider</h1>
<p>I just shipped the first issue of a new newsletter: <a href="https://appleuiinsider.com">Apple UI Insider</a>. It is a field guide to Apple’s UI rendering stack, Core Graphics, Core Text, Core Image, Core Animation, and SwiftUI, written from the inside of a clean-room renderer I built to match it.</p>
<p><strong>What each issue does.</strong> Every issue picks a corner of the stack and asks what each tier actually owns, where the boundary between two tiers runs, and which bugs live there specifically because of that boundary. Not “how to use SwiftUI.” Where SwiftUI stops owning the pixels and Core Animation starts. Core Animation does not shape text. Core Text does not composite your window. Core Graphics does not know SwiftUI identity. A surprising number of confusing bugs come from expecting one tier to quietly do another tier’s job.</p>
<p><strong>Every picture is drawn twice.</strong> That claim needs a way to check it, so each figure in the newsletter is rendered twice from the identical scene source: once by SlayerMotion, my clean-room renderer, and once by Apple’s own frameworks. The two outputs are compared and the differences are published alongside the picture, not hidden in a footnote.</p>
<p>I don’t just assert that the comparison is real, I make it falsifiable. Issue 1 ships a mutation proof: take the hero scene’s source, change exactly one fill to pure magenta, and re-run it through Apple’s own pipeline. The untouched render contains zero magenta pixels. The mutated one contains exactly 3,600, in exactly the region I changed, a 60 by 60 pixel patch and nothing else. If the twin renderer were faking agreement instead of actually reproducing Apple’s output, that number would be wrong.</p>
<p>That same discipline is what caught a real bug while I was building the issue. An early version of the animation twins showed the two renderers disagreeing on rotated layers by 3.7 to 3.9 percent, against a healthy baseline of about 0.1 percent for every other scene. That gap traced to a coordinate-flip bug in my own engine’s device-space compositing, not a rounding difference and not Apple’s fault. I fixed it, re-ran the exact same comparison, and the same scene now agrees to within 0.07 percent. The original, divergent renders are still in the issue’s proof bundle next to the fixed ones, because a caught bug is evidence too, not something to quietly delete.</p>
<p>Not every scene in the issue is a diagram. One of them is a vector dragon breathing particle fire, drawn entirely through the same graphics tier as everything else, paths, gradients, shadows, and replicated scales down its tail, then driven frame by frame into an animated GIF.</p>
<p><img src="https://aleahim.com/images/blog/apple-ui-insider/dragon.png" alt="A vector dragon breathing particle fire, drawn frame by frame through Apple’s Core Graphics pipeline from the SlayerMotion source"></p>
<p><em>Same discipline, less diagram. The dragon is one of the issue’s Core Animation scenes, rendered through Core Graphics and compared frame by frame.</em></p>
<p>Most of the twin pairs in the issue, dragon included, agree closely enough that you cannot tell the two renders apart by eye, which is the entire point, and why the measured percentage next to each figure is doing the real work rather than the picture alone.</p>
<p>I’d rather name the current edge than round up. Issue 1’s Apple twin is Core Graphics for every scene, so it compares rasterizers on identical, already-lowered geometry. It is not yet comparing my text engine against real Core Text shaping, or my image engine against a live <code>CIContext</code>, or my layer engine against an actual <code>CALayer</code> tree animating on screen. Those framework-native comparisons are exactly what the next issues build, one claim at a time, with the same measure-and-publish discipline, not a bigger promise made once and never checked again.</p>
<p><strong>Issue 1: The Map, Drawn Twice</strong> is live now. <a href="https://appleuiinsider.com/issues/the-map-drawn-twice/">Read it</a>, or <a href="https://appleuiinsider.com/">subscribe</a> to get the next one in your inbox first.</p>]]></content:encoded>
</item>
<item>
<title>SwiftUI 3D is Flat</title>
<link>https://aleahim.com/blog/swiftui-3d-is-flat/</link>
<guid isPermaLink="true">https://aleahim.com/blog/swiftui-3d-is-flat/</guid>
<pubDate>Sat, 04 Jul 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>SwiftUI&apos;s iOS and macOS 3D is per-view projected 2D output composited by painter&apos;s order, with no shared-space depth-sorted hierarchy, and the APIs that would fix it are visionOS-only, proven with a rendered counterexample and four executable witnesses</description>
<content:encoded><![CDATA[<h1>SwiftUI 3D is Flat</h1>
<p>SwiftUI looks like it does 3D.</p>
<p><code>rotation3DEffect</code> takes an axis, an anchor, an <code>anchorZ</code>, and a <code>perspective</code> parameter. <code>projectionEffect</code> takes a full <code>ProjectionTransform</code>, and <code>ProjectionTransform</code> can even be initialized directly from a <code>CATransform3D</code>. A custom <code>GeometryEffect</code> hands you the view’s size and lets you return any projection matrix you can compute. Pose one view with these and it looks convincingly, beautifully three-dimensional.</p>
<p>So build a cube. Six faces, one shared space, rotate the camera. That is the simplest possible 3D scene, and pure SwiftUI on iOS and macOS cannot build it. I tested this thesis rather than assuming it: I wrote the counterexample, rendered it headlessly, and inspected the images, and the rendering corrected two of my own claims along the way.</p>
<p>Let me say the finding precisely, because the imprecise version is wrong. Do not say “SwiftUI has no 3D.” Say:</p>
<blockquote><p>SwiftUI’s iOS/macOS 3D is per-view projected 2D output composited by painter’s order. It has no shared-space, depth-sorted layer hierarchy.</p></blockquote>
<p>SwiftUI genuinely has per-view 3D projection: one view, one card, one face rotates in space with real perspective. What it lacks is a shared 3D coordinate space across sibling views and a per-frame depth ordering inside it. And the missing piece has a name: it is exactly what Core Animation’s <code>CATransformLayer</code> exists to provide.</p>
<h2>The smallest counterexample, pure SwiftUI, no bridge</h2>
<p>Here is a self-contained SwiftUI cube. No UIKit, no AppKit, no Core Animation import. It uses only <code>rotation3DEffect(perspective:)</code>, the real iOS/macOS 3D view effect. The faces are declared back-to-front for the rest pose, front face last so it paints on top when the cube faces you. That hand-sorted order is the whole point: SwiftUI never recomputes it as the cube rotates, so it is correct only at rest.</p>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">SwiftUI</span>

<span class="tok-keyword">struct</span> <span class="tok-type">FlatSwiftUICube</span><span class="tok-operator">:</span> <span class="tok-type">View</span> {
    <span class="tok-attribute">@State</span> <span class="tok-keyword">private</span> <span class="tok-keyword">var</span> yaw <span class="tok-operator">=</span> <span class="tok-number">0.0</span>
    <span class="tok-attribute">@State</span> <span class="tok-keyword">private</span> <span class="tok-keyword">var</span> pitch <span class="tok-operator">=</span> <span class="tok-number">20.0</span>
    <span class="tok-keyword">private</span> <span class="tok-keyword">let</span> side<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span> <span class="tok-operator">=</span> <span class="tok-number">120</span>

    <span class="tok-keyword">var</span> body<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">View</span> {
        <span class="tok-type">VStack</span>(spacing<span class="tok-operator">:</span> <span class="tok-number">24</span>) {
            <span class="tok-type">ZStack</span> {
                <span class="tok-comment">// Back-to-front for the rest pose: front (2) declared LAST so it wins at yaw 0.</span>
                <span class="tok-function">face</span>(<span class="tok-operator">.</span>yellow, <span class="tok-string">"4"</span>, angle<span class="tok-operator">:</span> <span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">180</span>), ax<span class="tok-keyword">is</span><span class="tok-operator">:</span> (<span class="tok-number">0</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>)) <span class="tok-comment">// back</span>
                <span class="tok-function">face</span>(<span class="tok-operator">.</span>orange, <span class="tok-string">"5"</span>, angle<span class="tok-operator">:</span> <span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">90</span>),  ax<span class="tok-keyword">is</span><span class="tok-operator">:</span> (<span class="tok-number">1</span>, <span class="tok-number">0</span>, <span class="tok-number">0</span>)) <span class="tok-comment">// top</span>
                <span class="tok-function">face</span>(<span class="tok-operator">.</span>purple, <span class="tok-string">"6"</span>, angle<span class="tok-operator">:</span> <span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">-90</span>), ax<span class="tok-keyword">is</span><span class="tok-operator">:</span> (<span class="tok-number">1</span>, <span class="tok-number">0</span>, <span class="tok-number">0</span>)) <span class="tok-comment">// bottom</span>
                <span class="tok-function">face</span>(<span class="tok-operator">.</span>red,    <span class="tok-string">"1"</span>, angle<span class="tok-operator">:</span> <span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">-90</span>), ax<span class="tok-keyword">is</span><span class="tok-operator">:</span> (<span class="tok-number">0</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>)) <span class="tok-comment">// left</span>
                <span class="tok-function">face</span>(<span class="tok-operator">.</span>green,  <span class="tok-string">"3"</span>, angle<span class="tok-operator">:</span> <span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">90</span>),  ax<span class="tok-keyword">is</span><span class="tok-operator">:</span> (<span class="tok-number">0</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>)) <span class="tok-comment">// right</span>
                <span class="tok-function">face</span>(<span class="tok-operator">.</span>blue,   <span class="tok-string">"2"</span>, angle<span class="tok-operator">:</span> <span class="tok-operator">.</span><span class="tok-function">degrees</span>(<span class="tok-number">0</span>),   ax<span class="tok-keyword">is</span><span class="tok-operator">:</span> (<span class="tok-number">0</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>)) <span class="tok-comment">// front</span>
            }
            <span class="tok-comment">// Rotate the WHOLE assembly. There is no shared 3D space, so this is just one</span>
            <span class="tok-comment">// more projection applied on top of the already-projected faces.</span>
            <span class="tok-operator">.</span><span class="tok-function">rotation3DEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(pitch), ax<span class="tok-keyword">is</span><span class="tok-operator">:</span> (<span class="tok-number">1</span>, <span class="tok-number">0</span>, <span class="tok-number">0</span>), perspective<span class="tok-operator">:</span> <span class="tok-number">0.5</span>)
            <span class="tok-operator">.</span><span class="tok-function">rotation3DEffect</span>(<span class="tok-operator">.</span><span class="tok-function">degrees</span>(yaw),   ax<span class="tok-keyword">is</span><span class="tok-operator">:</span> (<span class="tok-number">0</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>), perspective<span class="tok-operator">:</span> <span class="tok-number">0.5</span>)
            <span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">260</span>, height<span class="tok-operator">:</span> <span class="tok-number">260</span>)

            <span class="tok-type">Slider</span>(value<span class="tok-operator">:</span> $yaw,   <span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-number">0...360</span>)
            <span class="tok-type">Slider</span>(value<span class="tok-operator">:</span> $pitch, <span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-number">-90...90</span>)
        }
        <span class="tok-operator">.</span><span class="tok-function">padding</span>()
    }

    <span class="tok-keyword">private</span> <span class="tok-keyword">func</span> <span class="tok-function">face</span>(_ color<span class="tok-operator">:</span> <span class="tok-type">Color</span>, _ label<span class="tok-operator">:</span> <span class="tok-type">String</span>,
                      angle<span class="tok-operator">:</span> <span class="tok-type">Angle</span>, ax<span class="tok-keyword">is</span><span class="tok-operator">:</span> (x<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>, y<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>, z<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>)) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-keyword">some</span> <span class="tok-type">View</span> {
        <span class="tok-type">ZStack</span> {
            <span class="tok-type">RoundedRectangle</span>(corner<span class="tok-type">Radius</span><span class="tok-operator">:</span> <span class="tok-number">8</span>)<span class="tok-operator">.</span><span class="tok-function">fill</span>(color<span class="tok-operator">.</span><span class="tok-function">opacity</span>(<span class="tok-number">0.55</span>))
            <span class="tok-type">RoundedRectangle</span>(corner<span class="tok-type">Radius</span><span class="tok-operator">:</span> <span class="tok-number">8</span>)<span class="tok-operator">.</span><span class="tok-function">stroke</span>(color, line<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-number">2</span>)
            <span class="tok-type">Text</span>(label)<span class="tok-operator">.</span><span class="tok-function">font</span>(<span class="tok-operator">.</span>title)<span class="tok-operator">.</span><span class="tok-function">bold</span>()<span class="tok-operator">.</span><span class="tok-function">foregroundStyle</span>(<span class="tok-operator">.</span>white)
        }
        <span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> side, height<span class="tok-operator">:</span> side)
        <span class="tok-comment">// anchorZ pivots the rotation half a side behind the face. It is the ONLY way to</span>
        <span class="tok-comment">// fake shared-space placement on iOS/macOS, because there is no z-translation in a</span>
        <span class="tok-comment">// shared 3D coordinate space (transform3DEffect is visionOS-only).</span>
        <span class="tok-operator">.</span><span class="tok-function">rotation3DEffect</span>(angle, ax<span class="tok-keyword">is</span><span class="tok-operator">:</span> ax<span class="tok-keyword">is</span>, anchor<span class="tok-type">Z</span><span class="tok-operator">:</span> <span class="tok-operator">-</span>side <span class="tok-operator">/</span> <span class="tok-number">2</span>, perspective<span class="tok-operator">:</span> <span class="tok-number">0.5</span>)
    }
}</code></pre>
<p>I rendered this with <code>ImageRenderer</code> at <code>pitch = 20</code> across a yaw sweep and inspected it image by image. The observations, rendered, not asserted:</p>
<ul><li><p><strong>At <code>yaw = 0</code>, the rest pose:</strong> the blue front face reads on top and the assembly reads as “a cube facing you.” But look closer: it is a <em>splayed frustum, not a closed cube</em>. The sides fan outward, because the <code>anchorZ</code> pivot cannot push a face out along its normal in a shared space. The correct static shape is already out of reach. That is itself evidence for the thesis.</p></li><li><p><strong>At <code>yaw = 120</code>:</strong> the blue front face has turned to face away from the viewer, yet it still dominates the center, painted on top, its label mirrored. A real cube at this angle shows mostly side and back faces with the front occluded.</p></li><li><p><strong>At <code>yaw = 180</code>:</strong> the front face points fully away, so a depth-sorted cube shows the yellow back face. Instead the yellow face is completely hidden and the blue front face still fills the center, label reversed. This is the unambiguous failure: no depth sort, the declared-last face always wins.</p></li></ul>
<p>An earlier draft of this analysis asserted the behavior from reasoning, and the render corrected it twice: my original face order buried the front face so the cube was wrong even at rest, and the “cube” at rest is really a frustum. The thesis survived both corrections and came out stronger, which is exactly why a thesis has to be tested.</p>
<p>The failure also fits in one automatable line: at <code>yaw = 180</code> the center pixel of the SwiftUI render is blue, the wrong winner. Render the Core Animation cube at the matching pose and the center is the true back face. Same pose, opposite winner: painter’s order versus depth sort.</p>
<p><img src="https://aleahim.com/images/blog/swiftui-3d-is-flat/flat-vs-cube.jpg" alt="Pure SwiftUI on the left: a splayed frustum with BACK painting over FRONT. Core Animation on the right: a closed cube, correct at every angle."></p>
<p>Here is the same failure live, in the pure SwiftUI macOS witness from the <a href="https://codeberg.org/Mihaela/applecube">AppleCube repository</a>:</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 315 / 560;">
<div class="td-embed-frame">
<iframe
  class="td-embed-iframe"
  src="https://www.youtube-nocookie.com/embed/uGORYd5CQwU"
  title="SwiftUI 3D Is Flat, macOS SwiftUI witness"
  loading="lazy"
  allowfullscreen
  referrerpolicy="strict-origin-when-cross-origin"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
></iframe>
</div>
</figure>
<p><img src="https://aleahim.com/images/blog/swiftui-3d-is-flat/iphone-swiftui-flat.jpg" alt="The failure pose on iPhone: BACK paints over FRONT"></p>
<h2>What the APIs actually are, in Apple’s words</h2>
<p>The decisive evidence is not the demo. It is the documentation, read carefully. Two phrases decide the thesis, and both appear verbatim in Apple’s docs.</p>
<p>Core Animation’s <code>CATransformLayer</code> is documented as the class for “true 3D layer hierarchies, rather than the flattened hierarchy rendering model used by other layer types”, and, unlike normal layers, transform layers “do not flatten their sublayers into the plane at Z=0”.</p>
<p>SwiftUI’s <code>rotation3DEffect</code> on iOS and macOS “renders a view’s content as if it’s rotated” in three dimensions. <code>projectionEffect</code> “applies a projection transformation to this view’s rendered output”.</p>
<p>As-if-rotated rendered output is a 2D projection. It is not membership in a shared 3D scene. The full API picture:</p>
<table><thead><tr><th>API</th><th>What it does</th><th>Availability</th><th>Verdict for a shared-space cube</th></tr></thead><tbody><tr><td><code>CATransformLayer</code></td><td>True 3D layer hierarchies, sublayers not flattened into Z = 0</td><td>iOS 3.0+, macOS 10.6+</td><td>The primitive. Shared 3D space, depth preserved.</td></tr><tr><td><code>rotation3DEffect(_:axis:anchor:anchorZ:perspective:)</code></td><td>Renders content as if rotated in 3D</td><td>iOS 13+, macOS 10.15+</td><td>Per-view projection of rendered output. No shared space.</td></tr><tr><td><code>projectionEffect(_:)</code></td><td>Applies a projection to rendered output</td><td>iOS 13+, macOS 10.15+</td><td>Per-view 2D projection. No shared space.</td></tr><tr><td><code>transform3DEffect(_:)</code> with <code>AffineTransform3D</code></td><td>A real 3D transform, including z-translation</td><td>visionOS only</td><td>Not available on iOS/macOS.</td></tr><tr><td><code>perspectiveRotationEffect(_:axis:)</code></td><td>3D rotation with perspective</td><td>visionOS only</td><td>Not available on iOS/macOS.</td></tr><tr><td><code>rotation3DEffect(_:anchor:)</code> with <code>Rotation3D</code></td><td>Rotation by a true 3D rotation value</td><td>visionOS only</td><td>Not available on iOS/macOS.</td></tr></tbody></table>
<p>Read the bottom three rows again. The richer 3D view model exists. Apple built it, named it, shipped it, on visionOS, where the platform has a real depth model. On iOS and macOS those APIs are simply not offered. Nobody forgot 3D. The boundary is deliberate, which is what makes it worth studying.</p>
<h2>The SwiftUI filter</h2>
<p>So ask the question the way a SwiftUI architect would. Not “which Core Animation properties are missing?”, but:</p>
<blockquote><p>Given the Core Animation layer model as input, what subset did SwiftUI admit into its value-based view model, under what names, and at what scope?</p></blockquote>
<p>The answer is a filter, not a one-to-one wrapper. The input side is a persistent object graph: layers with <code>bounds</code>, <code>position</code>, <code>zPosition</code>, <code>anchorPoint</code>, <code>anchorPointZ</code>, a mutable <code>transform</code>, a parent <code>sublayerTransform</code>, a <code>sublayers</code> array, and compositor rules like depth sorting and <code>doubleSided</code>. The output side is SwiftUI’s view value: layout proposes a rectangle, modifiers derive another rendered result from it, the parent composites children in view order plus <code>zIndex</code>.</p>
<p>The filter rule:</p>
<blockquote><p><strong>SwiftUI admits only the pieces that can be expressed as value transforms of one view’s rendered rectangle. It does not admit API that turns a view subtree into a mutable layer object graph.</strong></p></blockquote>
<p>Run every relevant Core Animation input through that rule and you get exactly the API that shipped:</p>
<table><thead><tr><th>Core Animation input</th><th>SwiftUI output</th><th>Preserved</th><th>Collapsed or rejected</th><th>Consequence for the cube</th></tr></thead><tbody><tr><td><code>CALayer.anchorPoint</code></td><td><code>anchor: UnitPoint</code></td><td>The normalized 2D pivot.</td><td>The persistent layer field is gone. The anchor is an argument to one transform or layout operation.</td><td>You can pivot one view effect. You cannot rebase an enduring subtree.</td></tr><tr><td><code>CALayer.anchorPointZ</code></td><td><code>anchorZ</code> on <code>rotation3DEffect</code></td><td>A Z pivot for one 3D rotation.</td><td>Scoped to the modifier, not stored as layer geometry.</td><td><code>anchorZ: -side / 2</code> can hinge one face. It cannot create shared depth.</td></tr><tr><td><code>CALayer.transform</code></td><td><code>rotation3DEffect</code>, <code>projectionEffect</code>, <code>GeometryEffect</code> returning <code>ProjectionTransform</code></td><td>Per-view projection, initializable from <code>CATransform3D</code>.</td><td>Retained <code>CATransform3D</code> layer state is collapsed into a projection of rendered output.</td><td>One card flip can be correct. Six projected cards are still six siblings.</td></tr><tr><td><code>CALayer.sublayerTransform</code></td><td>Nothing on iOS/macOS</td><td>Nothing at parent-view level.</td><td>Rejected: no parent camera matrix over child views.</td><td>No single perspective shared by all faces, and no shared vanishing point.</td></tr><tr><td><code>CATransformLayer</code></td><td>Nothing on iOS/macOS</td><td>Nothing.</td><td>Rejected: no non-flattening child container.</td><td>This is the missing primitive. Without it, a cube is only a pose.</td></tr><tr><td><code>zPosition</code></td><td><code>zIndex</code></td><td>A draw-order priority.</td><td>Geometric depth collapsed into painter’s order.</td><td>The order can be chosen. It is never recomputed from camera depth.</td></tr><tr><td><code>CALayer.doubleSided</code></td><td>Nothing direct</td><td>Nothing direct.</td><td>Back-face culling is not exposed as a view-compositor rule.</td><td>A two-sided card swaps content manually, per-face simulation, not compositor culling.</td></tr></tbody></table>
<p>So yes, SwiftUI has anchors. The exact sentence matters: <strong>SwiftUI has transform anchors; it does not expose Core Animation’s layer anchor fields.</strong> <code>anchor</code> and <code>anchorZ</code> are not <code>CALayer.anchorPoint</code> and <code>anchorPointZ</code> under different names. They are filtered descendants of those ideas. SwiftUI kept the notion of a normalized pivot because it is useful inside a pure value transform, and rejected the durable layer-geometry object that would let a subtree behave like a mutable 3D model.</p>
<p>Why draw the line there? Because the filter is the price of SwiftUI’s core design. Views are values: <code>body</code> produces them, a long-lived dependency graph diffs them, and animatable attributes interpolate copies of their data, off the main thread for the built-in effects. Exposing <code>sublayerTransform</code>, <code>CATransformLayer</code>, or mutable layer geometry would let user code mutate an object graph underneath SwiftUI’s layout, diffing, identity, animation, and cross-platform rendering model. SwiftUI instead keeps the backing renderer private and offers value-level transformations. If I were designing SwiftUI, this is a coherent boundary and I would draw it too. It is also the scientific reason the cube proof fails in pure SwiftUI. Both facts are true at once.</p>
<h2>The positive control: the cube that works</h2>
<p>Claims need controls. The <a href="https://codeberg.org/Mihaela/applecube">AppleCube repository</a> keeps four executable targets, a positive and a negative witness on each platform:</p>
<table><thead><tr><th>Platform</th><th>Positive construction</th><th>Negative witness</th></tr></thead><tbody><tr><td>iPhone</td><td><code>Cube3DMobile</code>: UIKit host, Core Animation layer scene</td><td><code>SwiftUIFlatMobile</code>: pure SwiftUI flattening failure</td></tr><tr><td>macOS</td><td><code>Cube3DCAMac</code>: AppKit host, the same layer scene</td><td><code>SwiftUIFlatMac</code>: pure SwiftUI flattening failure</td></tr></tbody></table>
<p><img src="https://aleahim.com/images/blog/swiftui-3d-is-flat/all-four-witnesses.jpg" alt="All four witnesses, side by side"></p>
<p>The negative controls are deliberately pure: no <code>UIViewRepresentable</code>, no <code>NSViewRepresentable</code>, no hosted UIKit or AppKit, no Core Animation, no SceneKit, no RealityKit. Even the night-sky background respects the firewall: the layer demos drift their stars with <code>CAEmitterLayer</code>, while the SwiftUI demos draw theirs with <code>Canvas</code> and <code>TimelineView</code>, because borrowing <code>CAEmitterLayer</code> would quietly turn the negative control back into a Core Animation demo.</p>
<p>The positive construction is everything the filter rejected, used directly, and each step is precisely the thing SwiftUI cannot express:</p>
<ol><li><p><strong>One parent <code>CATransformLayer</code></strong> holds the six faces as siblings in a single 3D coordinate space. Because it is a transform layer, the faces are not flattened to Z = 0.</p></li><li><p><strong>Perspective lives on the parent, once</strong>, shared by every face. One camera for the whole object, which also means one shared vanishing point:</p></li></ol>
<pre><code class="language-swift">perspective<span class="tok-operator">.</span>m<span class="tok-number">34</span> <span class="tok-operator">=</span> <span class="tok-number">-1.0</span> <span class="tok-operator">/</span> <span class="tok-number">500.0</span>
transformed<span class="tok-type">Layer</span><span class="tok-operator">.</span>sublayer<span class="tok-type">Transform</span> <span class="tok-operator">=</span> perspective</code></pre>
<ol start="3"><li><p><strong>Each face is placed in true 3D by its own layer transform.</strong> The fold is a rotation per face, and the front face is a real <code>CATransform3DMakeTranslation(0, 0, zWidth)</code>, a genuine +Z translation in the shared space. That z placement is exactly what <code>anchorZ</code> cannot fake, which is why the SwiftUI version is a frustum.</p></li><li><p><strong>Rotating the whole object mutates the parent’s <code>sublayerTransform</code>.</strong> One rotation moves the entire shared space, all six faces together, and the renderer re-resolves occlusion from the shared geometry every frame. Back faces can even be culled with <code>isDoubleSided = false</code>, a compositor rule, not a content swap.</p></li></ol>
<p>I walked through this construction step by step in <a href="https://aleahim.com/blog/core-animation-3d-cube/">Core Animation Layers forming a 3D cube</a>; it comes straight from Apple’s 2011 session Core Animation Essentials, and it still works, character for character, fifteen years later.</p>
<p>Here are both positive witnesses recorded together, the AppKit and UIKit apps hosting the same layer scene at the same time, folding and rotating with correct occlusion at every angle:</p>
<p><img src="https://aleahim.com/images/blog/swiftui-3d-is-flat/appkit-uikit-cube.gif" alt="AppKit and UIKit, one Core Animation scene, recorded together"></p>
<p>And the macOS witness on its own:</p>
<figure class="td-embed" style="--td-embed-aspect-ratio: 560 / 420;">
<div class="td-embed-frame">
<iframe
  class="td-embed-iframe"
  src="https://www.youtube-nocookie.com/embed/Ce5JnQ8B7pI"
  title="Core Animation Cube 3D, macOS AppKit witness"
  loading="lazy"
  allowfullscreen
  referrerpolicy="strict-origin-when-cross-origin"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
></iframe>
</div>
</figure>
<p>This is not a novel reading of Core Animation. Nick Lockwood’s <em>iOS Core Animation: Advanced Techniques</em> describes the identical model and builds the identical six-face cube: any 3D surfaces in one scene must be siblings “because each parent flattens its children”, <code>CATransformLayer</code> “does not flatten its sublayers, so it can be used to construct a hierarchical 3D structure”, and the parent’s perspective transform means “the vanishing point is set as the center of the container layer, not set individually”. Apple’s documentation, the running code, and a standard text all name the same two ingredients: the single-camera <code>sublayerTransform</code> and the non-flattening container.</p>
<h2>Core Animation is 2.5D, and that makes the finding sharper</h2>
<p>The article should not overclaim in the other direction either. Core Animation is not a depth-buffered 3D engine. Its model is 2.5D: flat layer surfaces living in a 3D compositing space, with a compositor descended from the painter’s model. Four exact rules:</p>
<ol><li><p>An ordinary <code>CALayer</code> flattens its subtree into one flat surface; a 3D transform then warps that surface as a projected quad.</p></li><li><p><code>sublayerTransform</code> is the parent camera. It applies to sublayers only, never to the parent’s own content. This is where shared <code>m34</code> perspective belongs.</p></li><li><p><code>CATransformLayer</code> is the exception: a non-rendering container whose only job is to keep children unflattened, so their faces project independently in one shared space.</p></li><li><p>Depth is sorted, not buffered. Faces are ordered back-to-front in the shared space; there is no per-pixel z-buffer. Mutually intersecting quads are the hard case. A cube of non-intersecting faces is the clean case.</p></li></ol>
<p>So the missing thing in SwiftUI is not “a 3D GPU”. The missing public primitive is the retained layer-compositor machinery: <code>CATransformLayer</code>, parent <code>sublayerTransform</code>, <code>zPosition</code> as layer-space ordering, and <code>doubleSided</code> as a compositor back-face rule.</p>
<p>There is one more witness worth naming. I have been building a clean-room reconstruction of Core Animation’s layer model, and it arrived at the same boundary from the other direction: to reproduce Core Animation’s cube it had to implement precisely these primitives, the non-flattening transform layer, the parent camera, the two-pivot face projection, the back-to-front depth sort, and back-face culling by projected winding. Its tests hold those behaviors against a live Core Animation rendering oracle, with one honestly open residual, an off-center multi-child seam measurement. A reconstruction that independently converges on the same four primitives is evidence that the boundary is real, not an artifact of one demo.</p>
<h2>Card flips prove a different theorem</h2>
<p>The classic <code>GeometryEffect</code> card flip, which I walked through in <a href="https://aleahim.com/blog/swift-u-i-lab-advanced-animations/">SwiftUILab’s Advanced Animations</a>, is intentionally not one of the witnesses. The trick enters through an allowed opening in the filter: a <code>GeometryEffect</code> receives a <code>CGSize</code> and returns a <code>ProjectionTransform</code>, a pure transform of one rendered rectangle, which is exactly the abstraction SwiftUI permits. Deferring the front-to-back content swap until the card is edge-on makes one rectangle look two-sided, and the card is beautiful because a single rendered rectangle is precisely what SwiftUI is for.</p>
<p>But note what the swap is standing in for. In Core Animation, <code>doubleSided</code> defaults to true and setting it false culls a layer when it faces away from the camera, a compositor rule. The card trick has to swap content manually because no such rule exists at the SwiftUI view level. It adds no shared Z space, no depth sorting, no parent camera. A card asks whether one view can be projected. A cube asks whether six siblings can share a scene. Different theorem.</p>
<h2>Proof status</h2>
<p>Following the discipline from <a href="https://aleahim.com/blog/the-swiftui-oracle/">The SwiftUI Oracle</a>, the claim is split into labeled evidence, because “it looks right” is not a result:</p>
<table><thead><tr><th>Claim</th><th>Status</th><th>Evidence</th></tr></thead><tbody><tr><td>SwiftUI exposes per-view projection, not a retained 3D hierarchy.</td><td>documented</td><td><code>rotation3DEffect(anchor:anchorZ:perspective:)</code> and <code>projectionEffect</code> act on rendered output. No <code>sublayerTransform</code>, no <code>CATransformLayer</code>, no depth-sorted container on iOS/macOS.</td></tr><tr><td>The richer 3D view model exists, elsewhere.</td><td>documented</td><td><code>transform3DEffect</code>, <code>perspectiveRotationEffect</code>, and the <code>Rotation3D</code> form of <code>rotation3DEffect</code> are visionOS-only.</td></tr><tr><td>The pure SwiftUI cube fails under rotation.</td><td>witnessed</td><td>The rendered yaw sweep: a frustum at rest, the front face painting on top after turning away at 120 and 180 degrees. The repo’s <code>SwiftUIFlatMobile</code> and <code>SwiftUIFlatMac</code> keep the failure visible and scripted.</td></tr><tr><td>The rejected primitives exist one level down.</td><td>documented</td><td><code>CATransformLayer</code> is documented as the non-flattening true-3D container; <code>sublayerTransform</code>, <code>zPosition</code>, <code>anchorPointZ</code>, and <code>doubleSided</code> are public layer API.</td></tr><tr><td>The real cube runs on iPhone and macOS.</td><td>witnessed</td><td><code>Cube3DMobile</code> and <code>Cube3DCAMac</code> host the same layer-only scene from UIKit and AppKit.</td></tr><tr><td>A clean-room reconstruction needs the same primitives.</td><td>witnessed</td><td>The Core Animation reconstruction independently implements the transform layer, parent camera, depth sort, and culling, gated against a live rendering oracle, with one disclosed open seam measurement.</td></tr><tr><td>Pixel-for-pixel equivalence to Apple’s compositor, inside AppleCube.</td><td>blocked</td><td>No pixel oracle in that repo yet. Its evidence is documented API surface plus executable witnesses.</td></tr></tbody></table>
<p>And the honest labeling that keeps all of this defensible:</p>
<ul><li><p>The AppleCube demo is labeled what it is: a UIKit/AppKit host with a Core Animation layer scene. It is not “pure SwiftUI 3D” and does not claim to be.</p></li><li><p>The counterexample above is genuinely pure SwiftUI, and it is labeled as what it is: a SwiftUI cube that demonstrates the flattening limit, not a working cube.</p></li><li><p>If you need a real cube inside a SwiftUI app on iOS or macOS today, the honest construction is a SwiftUI host wrapping the <code>CATransformLayer</code> scene through a representable, or SceneKit, or RealityKit. None of those is “pure SwiftUI 3D”.</p></li></ul>
<h2>Run it yourself</h2>
<p>Everything is in the <a href="https://codeberg.org/Mihaela/applecube">AppleCube repository</a>, including the recording scenarios that drive the failure poses reproducibly:</p>
<pre><code class="language-sh">xcodebuild \
  <span class="tok-operator">-</span>project Cube<span class="tok-number">3</span>DCA<span class="tok-operator">/</span>Cube<span class="tok-number">3</span>DCA<span class="tok-operator">.</span>xcodeproj \
  <span class="tok-operator">-</span>scheme SwiftUIFlatMobile \
  <span class="tok-operator">-</span>configuration Debug \
  <span class="tok-operator">-</span>destination <span class="tok-string">'platform=iOS Simulator,name=iPhone 17'</span> \
  build</code></pre>
<p>Swap the scheme for <code>Cube3DMobile</code>, <code>Cube3DCAMac</code>, or <code>SwiftUIFlatMac</code> for the other three witnesses.</p>
<p>In <a href="https://aleahim.com/blog/morlocks-built-swiftui/">The Morlocks Built SwiftUI</a> I argued that the foundation never left. This article is the constructive version of that argument, read off the API surface itself and then rendered to check. SwiftUI’s architects looked at the layer model, kept everything that could be expressed as a value transform of one rectangle, collapsed depth into draw order, and declined to expose the scene, then built the fuller 3D model where the platform demanded it, on visionOS. That decision is why your app animates smoothly without you ever thinking about the render loop. It is also why, when you finally need the cube on iOS or macOS, you will find it one hosting view below the boundary they drew.</p>]]></content:encoded>
</item>
<item>
<title>The SwiftUI Oracle: Measuring a Clean Room Against the Real Thing</title>
<link>https://aleahim.com/blog/the-swiftui-oracle/</link>
<guid isPermaLink="true">https://aleahim.com/blog/the-swiftui-oracle/</guid>
<pubDate>Sat, 27 Jun 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>How I prove a from-scratch SwiftUI engine is correct by holding it against real SwiftUI in 125 differential tests, with the actual code, the harness, the firewall, and the floating-point floor that makes agreement mean identical</description>
<content:encoded><![CDATA[<h1>The SwiftUI Oracle: Measuring a Clean Room Against the Real Thing</h1>
<p>In the last post I claimed I had measured SwiftUI until its behavior was predictable. This
post is the receipts. It is for Swift developers, so it is mostly code: the test harness,
the firewall that keeps it honest, and the differential tests that hold a from-scratch
engine against the real framework. If you have ever wondered what it would take to <em>prove</em>
you understand SwiftUI rather than assert it, this is one answer.</p>
<p>The engine is called PureView. It is a clean-room reimplementation of SwiftUI’s semantics:
the attribute graph, identity, layout, animation, and lowering to a display list. It never
imports SwiftUI. The proof that it is faithful is a separate test target that <em>does</em> import
SwiftUI and compares the two, value for value.</p>
<p><img src="https://aleahim.com/images/blog/the-swiftui-oracle/1-two-pieces.jpg" alt="Our engine, and the real framework as the answer key"></p>
<h2>What “oracle” means here</h2>
<p>In testing, an <strong>oracle</strong> is the source of the correct answer: the thing that tells you
whether a result is right. Our oracle is real SwiftUI itself. For any scene, we ask the
real framework what it does, and that answer is the ground truth we grade the engine
against. The engine is the work; SwiftUI is the answer key.</p>
<h2>The firewall: the engine may never import SwiftUI</h2>
<p>A measurement is worthless if the instrument can cheat. If the engine were allowed to call
SwiftUI, any agreement would be suspect, because the engine could simply forward to the
framework it claims to reproduce. So the engine is sealed off, and the seal is not a
convention. It is a test that fails <code>swift test</code> if a UI-framework import ever appears in
the engine sources.</p>
<p><img src="https://aleahim.com/images/blog/the-swiftui-oracle/2-firewall.jpg" alt="The firewall: the engine cannot peek"></p>
<pre><code class="language-swift"><span class="tok-attribute">@Suite</span>(<span class="tok-string">"Engine import confinement"</span>)
<span class="tok-keyword">struct</span> <span class="tok-type">EngineImportConfinementTests</span> {
    <span class="tok-attribute">@Test</span>(<span class="tok-string">"Sources/PureView imports no UI framework"</span>)
    <span class="tok-keyword">func</span> <span class="tok-function">engineImportsNoUIFramework</span>() <span class="tok-keyword">throws</span> {
        <span class="tok-keyword">let</span> forbidden <span class="tok-operator">=</span> [<span class="tok-string">"SwiftUI"</span>, <span class="tok-string">"UIKit"</span>, <span class="tok-string">"AppKit"</span>, <span class="tok-string">"WatchKit"</span>]
        <span class="tok-comment">// #filePath = &lt;root&gt;/Tests/PureViewTests/&lt;this file&gt;; climb to &lt;root&gt;/Sources/PureView.</span>
        <span class="tok-keyword">let</span> engine<span class="tok-type">Root</span> <span class="tok-operator">=</span> <span class="tok-type">URL</span>(file<span class="tok-type">Path</span><span class="tok-operator">:</span> <span class="tok-attribute">#filePath</span>)
            <span class="tok-operator">.</span><span class="tok-function">deletingLastPathComponent</span>() <span class="tok-comment">// PureViewTests</span>
            <span class="tok-operator">.</span><span class="tok-function">deletingLastPathComponent</span>() <span class="tok-comment">// Tests</span>
            <span class="tok-operator">.</span><span class="tok-function">deletingLastPathComponent</span>() <span class="tok-comment">// &lt;root&gt;</span>
            <span class="tok-operator">.</span><span class="tok-function">appending</span>(path<span class="tok-operator">:</span> <span class="tok-string">"Sources/PureView"</span>)

        <span class="tok-keyword">let</span> file<span class="tok-type">Manager</span> <span class="tok-operator">=</span> <span class="tok-type">FileManager</span><span class="tok-operator">.</span><span class="tok-keyword">default</span>
        <span class="tok-keyword">let</span> enumerator <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-attribute">#require</span>(
            file<span class="tok-type">Manager</span><span class="tok-operator">.</span><span class="tok-function">enumerator</span>(at<span class="tok-operator">:</span> engine<span class="tok-type">Root</span>, including<span class="tok-type">PropertiesForKeys</span><span class="tok-operator">:</span> <span class="tok-literal">nil</span>),
            <span class="tok-string">"engine source root must exist at \(engineRoot.path)"</span>
        )

        <span class="tok-keyword">func</span> <span class="tok-function">importsForbidden</span>(_ line<span class="tok-operator">:</span> <span class="tok-type">String</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Bool</span> {
            forbidden<span class="tok-operator">.</span>contains { framework <span class="tok-keyword">in</span>
                line <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-string">"import \(framework)"</span>
                    <span class="tok-operator">|</span><span class="tok-operator">|</span> line <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-string">"@testable import \(framework)"</span>
                    <span class="tok-operator">|</span><span class="tok-operator">|</span> line<span class="tok-operator">.</span><span class="tok-function">hasPrefix</span>(<span class="tok-string">"import \(framework)."</span>)
            }
        }

        <span class="tok-keyword">var</span> offenders<span class="tok-operator">:</span> [<span class="tok-type">String</span>] <span class="tok-operator">=</span> []
        <span class="tok-keyword">for</span> <span class="tok-keyword">case</span> <span class="tok-keyword">let</span> url <span class="tok-keyword">as</span> <span class="tok-type">URL</span> <span class="tok-keyword">in</span> enumerator <span class="tok-keyword">where</span> url<span class="tok-operator">.</span>path<span class="tok-keyword">Extension</span> <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-string">"swift"</span> {
            <span class="tok-keyword">let</span> source <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-type">String</span>(contents<span class="tok-type">Of</span><span class="tok-operator">:</span> url, encoding<span class="tok-operator">:</span> <span class="tok-operator">.</span>utf<span class="tok-number">8</span>)
            <span class="tok-keyword">for</span> (index, line) <span class="tok-keyword">in</span> source<span class="tok-operator">.</span><span class="tok-function">split</span>(separator<span class="tok-operator">:</span> <span class="tok-string">"\n"</span>, omitting<span class="tok-type">EmptySubsequences</span><span class="tok-operator">:</span> <span class="tok-literal">false</span>)<span class="tok-operator">.</span><span class="tok-function">enumerated</span>() {
                <span class="tok-keyword">let</span> trimmed <span class="tok-operator">=</span> line<span class="tok-operator">.</span><span class="tok-function">trimmingCharacters</span>(<span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-operator">.</span>whitespaces)
                <span class="tok-keyword">if</span> <span class="tok-function">importsForbidden</span>(trimmed) {
                    offenders<span class="tok-operator">.</span><span class="tok-function">append</span>(<span class="tok-string">"\(url.lastPathComponent):\(index + 1): \(trimmed)"</span>)
                }
            }
        }

        <span class="tok-attribute">#expect</span>(offenders<span class="tok-operator">.</span>is<span class="tok-type">Empty</span>, <span class="tok-string">"engine must not import a UI framework, found: \(offenders)"</span>)
    }
}</code></pre>
<p>SwiftUI, UIKit, and AppKit are system frameworks, so a stray <code>import SwiftUI</code> in an engine
file would compile green and ship undetected. The convention is not enough; this test makes
the leak fail the build. That is the whole integrity story in thirty lines.</p>
<h2>The shape of every test: do it twice, compare</h2>
<p>Every oracle test has the same skeleton. Describe a scene. Run it in real SwiftUI and
record the answer. Run the same scene in the engine. Assert the two agree, to the
floating-point floor.</p>
<p><img src="https://aleahim.com/images/blog/the-swiftui-oracle/3-do-it-twice.jpg" alt="One scene, run in both, compared to one millionth"></p>
<h2>The harness: running real SwiftUI headless</h2>
<p>To use SwiftUI as the oracle we have to run it for real, with no app and no screen. The
harness hosts a view in an offscreen window, lets it run a genuine update cycle, then reads
the resolved geometry back out through a preference-key probe.</p>
<pre><code class="language-swift"><span class="tok-keyword">private</span> <span class="tok-keyword">struct</span> <span class="tok-type">FrameKey</span><span class="tok-operator">:</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">PreferenceKey</span> {
    <span class="tok-keyword">static</span> <span class="tok-keyword">let</span> default<span class="tok-type">Value</span><span class="tok-operator">:</span> [<span class="tok-type">String</span><span class="tok-operator">:</span> <span class="tok-type">CGRect</span>] <span class="tok-operator">=</span> [<span class="tok-operator">:</span>]
    <span class="tok-keyword">static</span> <span class="tok-keyword">func</span> <span class="tok-function">reduce</span>(value<span class="tok-operator">:</span> <span class="tok-keyword">inout</span> [<span class="tok-type">String</span><span class="tok-operator">:</span> <span class="tok-type">CGRect</span>], next<span class="tok-type">Value</span><span class="tok-operator">:</span> () <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> [<span class="tok-type">String</span><span class="tok-operator">:</span> <span class="tok-type">CGRect</span>]) {
        value<span class="tok-operator">.</span><span class="tok-function">merge</span>(<span class="tok-function">nextValue</span>(), uniquing<span class="tok-type">KeysWith</span><span class="tok-operator">:</span> { _, new <span class="tok-keyword">in</span> new })
    }
}

<span class="tok-keyword">extension</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">View</span> {
    <span class="tok-comment">/// Tag a view so the oracle records its resolved frame, in root coordinates.</span>
    <span class="tok-keyword">func</span> <span class="tok-function">probe</span>(_ id<span class="tok-operator">:</span> <span class="tok-type">String</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-keyword">some</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">View</span> {
        <span class="tok-function">background</span>(
            <span class="tok-type">GeometryReader</span> { proxy <span class="tok-keyword">in</span>
                <span class="tok-type">Color</span><span class="tok-operator">.</span>clear<span class="tok-operator">.</span><span class="tok-function">preference</span>(key<span class="tok-operator">:</span> <span class="tok-type">FrameKey</span><span class="tok-operator">.</span><span class="tok-keyword">self</span>, value<span class="tok-operator">:</span> [id<span class="tok-operator">:</span> proxy<span class="tok-operator">.</span><span class="tok-function">frame</span>(<span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-operator">.</span><span class="tok-function">named</span>(k<span class="tok-type">Root</span>))])
            }
        )
    }
}

<span class="tok-attribute">@MainActor</span>
<span class="tok-keyword">func</span> <span class="tok-function">oracleFrames</span>(_ content<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">View</span>, root<span class="tok-type">Size</span><span class="tok-operator">:</span> <span class="tok-type">CGSize</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> [<span class="tok-type">String</span><span class="tok-operator">:</span> <span class="tok-type">CGRect</span>] {
    <span class="tok-keyword">let</span> box <span class="tok-operator">=</span> <span class="tok-type">FrameBox</span>()
    <span class="tok-keyword">let</span> view <span class="tok-operator">=</span> <span class="tok-type">ZStack</span>(alignment<span class="tok-operator">:</span> <span class="tok-operator">.</span>top<span class="tok-type">Leading</span>) { content }
        <span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> root<span class="tok-type">Size</span><span class="tok-operator">.</span>width, height<span class="tok-operator">:</span> root<span class="tok-type">Size</span><span class="tok-operator">.</span>height, alignment<span class="tok-operator">:</span> <span class="tok-operator">.</span>top<span class="tok-type">Leading</span>)
        <span class="tok-operator">.</span><span class="tok-function">coordinateSpace</span>(name<span class="tok-operator">:</span> k<span class="tok-type">Root</span>)
        <span class="tok-operator">.</span><span class="tok-function">onPreferenceChange</span>(<span class="tok-type">FrameKey</span><span class="tok-operator">.</span><span class="tok-keyword">self</span>) { box<span class="tok-operator">.</span>frames <span class="tok-operator">=</span> $<span class="tok-number">0</span> }
        <span class="tok-operator">.</span><span class="tok-function">environment</span>(\<span class="tok-operator">.</span>display<span class="tok-type">Scale</span>, <span class="tok-number">2</span>)   <span class="tok-comment">// pin the pixel grid for cross-machine determinism</span>

    <span class="tok-keyword">let</span> host <span class="tok-operator">=</span> <span class="tok-type">NSHostingView</span>(root<span class="tok-type">View</span><span class="tok-operator">:</span> view)
    host<span class="tok-operator">.</span>frame <span class="tok-operator">=</span> <span class="tok-type">CGRect</span>(orig<span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-operator">.</span>zero, size<span class="tok-operator">:</span> root<span class="tok-type">Size</span>)
    <span class="tok-keyword">let</span> window <span class="tok-operator">=</span> <span class="tok-type">NSWindow</span>(content<span class="tok-type">Rect</span><span class="tok-operator">:</span> host<span class="tok-operator">.</span>frame, style<span class="tok-type">Mask</span><span class="tok-operator">:</span> [<span class="tok-operator">.</span>borderless],
                          backing<span class="tok-operator">:</span> <span class="tok-operator">.</span>buffered, <span class="tok-keyword">defer</span><span class="tok-operator">:</span> <span class="tok-literal">false</span>)
    window<span class="tok-operator">.</span>content<span class="tok-type">View</span> <span class="tok-operator">=</span> host
    host<span class="tok-operator">.</span><span class="tok-function">layoutSubtreeIfNeeded</span>()
    <span class="tok-function">pump</span>(until<span class="tok-operator">:</span> { <span class="tok-operator">!</span>box<span class="tok-operator">.</span>frames<span class="tok-operator">.</span>is<span class="tok-type">Empty</span> }, timeout<span class="tok-operator">:</span> <span class="tok-number">2</span>)
    <span class="tok-keyword">return</span> box<span class="tok-operator">.</span>frames
}

<span class="tok-comment">/// Spin the main run loop in 10 ms slices until `condition` holds or `timeout` elapses.</span>
<span class="tok-attribute">@MainActor</span>
<span class="tok-keyword">func</span> <span class="tok-function">pump</span>(until condition<span class="tok-operator">:</span> () <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Bool</span>, timeout<span class="tok-operator">:</span> <span class="tok-type">TimeInterval</span>) {
    <span class="tok-keyword">let</span> deadline <span class="tok-operator">=</span> <span class="tok-type">Date</span>()<span class="tok-operator">.</span><span class="tok-function">addingTimeInterval</span>(timeout)
    <span class="tok-keyword">while</span> <span class="tok-operator">!</span><span class="tok-function">condition</span>(), <span class="tok-type">Date</span>() <span class="tok-operator">&lt;</span> deadline {
        <span class="tok-type">RunLoop</span><span class="tok-operator">.</span>ma<span class="tok-keyword">in</span><span class="tok-operator">.</span><span class="tok-function">run</span>(until<span class="tok-operator">:</span> <span class="tok-type">Date</span>()<span class="tok-operator">.</span><span class="tok-function">addingTimeInterval</span>(<span class="tok-number">0.01</span>))
    }
}</code></pre>
<p><code>displayScale</code> is pinned to 2 so SwiftUI’s frame snapping is identical on a Retina machine
and a CI box. When we say “we measured what SwiftUI does,” this is the literal mechanism:
SwiftUI runs, and a <code>GeometryReader</code> reports its own layout system’s answer.</p>
<h2>Measuring the attribute graph: count the body re-runs</h2>
<p>The headline claim about SwiftUI is the cone: change one value, and only the views that
read it recompute. The problem is that a <code>body</code> re-run leaves no trace. So we give it one.
Each probe view bumps a counter inside its <code>body</code>. The invisible event becomes an integer.</p>
<pre><code class="language-swift"><span class="tok-comment">/// A reference counter mutated only on the main actor (inside `body`).</span>
<span class="tok-keyword">private</span> <span class="tok-keyword">final</span> <span class="tok-keyword">class</span> <span class="tok-type">BodyCounter</span><span class="tok-operator">:</span> <span class="tok-attribute">@unchecked</span> <span class="tok-type">Sendable</span> {
    <span class="tok-keyword">private</span>(set) <span class="tok-keyword">var</span> runs <span class="tok-operator">=</span> <span class="tok-number">0</span>
    <span class="tok-keyword">func</span> <span class="tok-function">bump</span>() { runs <span class="tok-operator">+</span><span class="tok-operator">=</span> <span class="tok-number">1</span> }
}

<span class="tok-keyword">private</span> <span class="tok-keyword">final</span> <span class="tok-keyword">class</span> <span class="tok-type">OracleModel</span><span class="tok-operator">:</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">ObservableObject</span> {
    <span class="tok-attribute">@SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">Published</span> <span class="tok-keyword">var</span> value<span class="tok-operator">:</span> <span class="tok-type">Int</span> <span class="tok-operator">=</span> <span class="tok-number">0</span>
}

<span class="tok-comment">/// Reads `model.value`, so it depends on the state.</span>
<span class="tok-keyword">private</span> <span class="tok-keyword">struct</span> <span class="tok-type">ReaderView</span><span class="tok-operator">:</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">View</span> {
    <span class="tok-attribute">@SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">ObservedObject</span> <span class="tok-keyword">var</span> model<span class="tok-operator">:</span> <span class="tok-type">OracleModel</span>
    <span class="tok-keyword">let</span> counter<span class="tok-operator">:</span> <span class="tok-type">BodyCounter</span>
    <span class="tok-keyword">var</span> body<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">View</span> {
        counter<span class="tok-operator">.</span><span class="tok-function">bump</span>()
        <span class="tok-keyword">return</span> <span class="tok-type">Text</span>(verbatim<span class="tok-operator">:</span> <span class="tok-string">"\(model.value)"</span>)
    }
}

<span class="tok-comment">/// Reads nothing from the model, so it must not re-evaluate when the state changes.</span>
<span class="tok-keyword">private</span> <span class="tok-keyword">struct</span> <span class="tok-type">IgnorerView</span><span class="tok-operator">:</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">View</span> {
    <span class="tok-keyword">let</span> counter<span class="tok-operator">:</span> <span class="tok-type">BodyCounter</span>
    <span class="tok-keyword">var</span> body<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">View</span> {
        counter<span class="tok-operator">.</span><span class="tok-function">bump</span>()
        <span class="tok-keyword">return</span> <span class="tok-type">Text</span>(verbatim<span class="tok-operator">:</span> <span class="tok-string">"static"</span>)
    }
}</code></pre>
<p><img src="https://aleahim.com/images/blog/the-swiftui-oracle/4-body-counter.jpg" alt="Counting which views recompute: the cone"></p>
<p>The test reads both counters, changes one value, waits for the reader to re-run, and then
drains the run loop a little longer so a stray re-run of the ignorer would be caught. Then
it builds the same shape in the engine’s <code>AttributeGraph</code> and asserts the cones match.</p>
<pre><code class="language-swift"><span class="tok-attribute">@Test</span>(<span class="tok-string">"only the view that reads state re-evaluates, and the engine cone agrees"</span>)
<span class="tok-keyword">func</span> <span class="tok-function">bodyEvalConeMatchesEngine</span>() {
    <span class="tok-comment">// Ground truth from real SwiftUI.</span>
    <span class="tok-keyword">let</span> swift<span class="tok-type">UI</span> <span class="tok-operator">=</span> <span class="tok-function">swiftUIBodyEvalDifferential</span>()
    <span class="tok-attribute">#expect</span>(swift<span class="tok-type">UI</span><span class="tok-operator">.</span>reader<span class="tok-type">Reran</span>,  <span class="tok-string">"SwiftUI: the reader's body should re-run on the state change"</span>)
    <span class="tok-attribute">#expect</span>(<span class="tok-operator">!</span>swift<span class="tok-type">UI</span><span class="tok-operator">.</span>ignorer<span class="tok-type">Reran</span>, <span class="tok-string">"SwiftUI: the ignorer's body should not re-run"</span>)

    <span class="tok-comment">// The same shape modeled in the engine: a source, a reader, an ignorer.</span>
    <span class="tok-keyword">let</span> graph <span class="tok-operator">=</span> <span class="tok-type">AttributeGraph</span>()
    <span class="tok-keyword">let</span> state <span class="tok-operator">=</span> <span class="tok-type">Attribute</span>(graph<span class="tok-operator">:</span> graph, value<span class="tok-operator">:</span> <span class="tok-number">0</span>)
    <span class="tok-keyword">let</span> reader <span class="tok-operator">=</span> <span class="tok-type">Attribute</span>(graph<span class="tok-operator">:</span> graph) { _ <span class="tok-keyword">in</span> state<span class="tok-operator">.</span>value }
    <span class="tok-keyword">let</span> ignorer <span class="tok-operator">=</span> <span class="tok-type">Attribute</span>(graph<span class="tok-operator">:</span> graph) { _ <span class="tok-keyword">in</span> <span class="tok-number">0</span> }
    _ <span class="tok-operator">=</span> reader<span class="tok-operator">.</span>value
    _ <span class="tok-operator">=</span> ignorer<span class="tok-operator">.</span>value
    <span class="tok-keyword">let</span> reader<span class="tok-type">Before</span> <span class="tok-operator">=</span> reader<span class="tok-operator">.</span>evaluation<span class="tok-type">Count</span>
    <span class="tok-keyword">let</span> ignorer<span class="tok-type">Before</span> <span class="tok-operator">=</span> ignorer<span class="tok-operator">.</span>evaluation<span class="tok-type">Count</span>

    state<span class="tok-operator">.</span><span class="tok-function">setValue</span>(<span class="tok-number">1</span>)
    _ <span class="tok-operator">=</span> reader<span class="tok-operator">.</span>value
    _ <span class="tok-operator">=</span> ignorer<span class="tok-operator">.</span>value

    <span class="tok-comment">// The differential: the engine's invalidation cone matches SwiftUI's.</span>
    <span class="tok-attribute">#expect</span>((reader<span class="tok-operator">.</span>evaluation<span class="tok-type">Count</span>  <span class="tok-operator">&gt;</span> reader<span class="tok-type">Before</span>)  <span class="tok-operator">=</span><span class="tok-operator">=</span> swift<span class="tok-type">UI</span><span class="tok-operator">.</span>reader<span class="tok-type">Reran</span>)
    <span class="tok-attribute">#expect</span>((ignorer<span class="tok-operator">.</span>evaluation<span class="tok-type">Count</span> <span class="tok-operator">&gt;</span> ignorer<span class="tok-type">Before</span>) <span class="tok-operator">=</span><span class="tok-operator">=</span> swift<span class="tok-type">UI</span><span class="tok-operator">.</span>ignorer<span class="tok-type">Reran</span>)
}</code></pre>
<p>Proving an <em>absence</em> is the subtle part. To show the ignorer stayed put, the test waits for
the expected re-run and then drains briefly for a stray. The engine side is deterministic
and is the real regression catcher; the bounded wait on the SwiftUI side can only catch a
stray, never manufacture a false pass.</p>
<h2>Measuring layout: probe the resolved frame</h2>
<p>Layout is the largest area, because there is the most to pin down. Each test lays the scene
out in real SwiftUI, reads back every subview’s frame through the probe, and asserts the
engine places each node at the same coordinates.</p>
<p><img src="https://aleahim.com/images/blog/the-swiftui-oracle/8-layout-negotiation.jpg" alt="Layout is a polite negotiation"></p>
<pre><code class="language-swift"><span class="tok-attribute">@Test</span>(<span class="tok-string">"Frame centering matches real SwiftUI"</span>)
<span class="tok-keyword">func</span> <span class="tok-function">frameCentering</span>() {
    <span class="tok-keyword">let</span> leaf <span class="tok-operator">=</span> <span class="tok-type">Color</span><span class="tok-operator">.</span>clear<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">20</span>, height<span class="tok-operator">:</span> <span class="tok-number">20</span>)<span class="tok-operator">.</span><span class="tok-function">probe</span>(<span class="tok-string">"child"</span>)
    <span class="tok-keyword">let</span> container <span class="tok-operator">=</span> leaf<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">30</span>, height<span class="tok-operator">:</span> <span class="tok-number">30</span>)<span class="tok-operator">.</span><span class="tok-function">probe</span>(<span class="tok-string">"container"</span>)
    <span class="tok-keyword">let</span> oracle <span class="tok-operator">=</span> <span class="tok-function">oracleFrames</span>(container, root<span class="tok-type">Size</span><span class="tok-operator">:</span> <span class="tok-type">CGSize</span>(width<span class="tok-operator">:</span> <span class="tok-number">100</span>, height<span class="tok-operator">:</span> <span class="tok-number">100</span>))
    <span class="tok-attribute">#expect</span>(<span class="tok-operator">!</span>oracle<span class="tok-operator">.</span>is<span class="tok-type">Empty</span>, <span class="tok-string">"oracle produced no frames (headless measurement failed)"</span>)

    <span class="tok-keyword">let</span> node <span class="tok-operator">=</span> <span class="tok-type">FrameLayout</span>(width<span class="tok-operator">:</span> <span class="tok-number">30</span>, height<span class="tok-operator">:</span> <span class="tok-number">30</span>, <span class="tok-type">FixedLeaf</span>(<span class="tok-type">Size</span>(width<span class="tok-operator">:</span> <span class="tok-number">20</span>, height<span class="tok-operator">:</span> <span class="tok-number">20</span>)))
    <span class="tok-keyword">let</span> engine <span class="tok-operator">=</span> node<span class="tok-operator">.</span><span class="tok-function">layout</span>(<span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-type">Size</span>(width<span class="tok-operator">:</span> <span class="tok-number">100</span>, height<span class="tok-operator">:</span> <span class="tok-number">100</span>))

    <span class="tok-keyword">if</span> <span class="tok-keyword">let</span> oc <span class="tok-operator">=</span> oracle[<span class="tok-string">"container"</span>] {
        <span class="tok-attribute">#expect</span>(<span class="tok-function">close</span>(oc, <span class="tok-function">cg</span>(engine<span class="tok-operator">.</span>frame)), <span class="tok-string">"container: oracle \(oc) vs engine \(cg(engine.frame))"</span>)
    }
    <span class="tok-keyword">if</span> <span class="tok-keyword">let</span> ch <span class="tok-operator">=</span> oracle[<span class="tok-string">"child"</span>] {
        <span class="tok-attribute">#expect</span>(<span class="tok-function">close</span>(ch, <span class="tok-function">cg</span>(engine<span class="tok-operator">.</span>children[<span class="tok-number">0</span>]<span class="tok-operator">.</span>frame)), <span class="tok-string">"child: oracle \(ch) vs engine \(cg(engine.children[0].frame))"</span>)
    }
}</code></pre>
<p><code>close</code> is where the rigor lives. The tolerance absorbs only <code>CGFloat</code> round-trip, nothing
more.</p>
<pre><code class="language-swift"><span class="tok-comment">/// The engine and SwiftUI must produce the *same* frame, not a close one. This 1e-6</span>
<span class="tok-comment">/// absorbs only `CGFloat` round-trip representation. A residual above it is a real</span>
<span class="tok-comment">/// divergence, never slack: re-derive the rule, do not widen the bound.</span>
<span class="tok-keyword">let</span> exact<span class="tok-type">Floor</span><span class="tok-operator">:</span> <span class="tok-type">CGFloat</span> <span class="tok-operator">=</span> <span class="tok-number">1</span>e<span class="tok-number">-6</span>

<span class="tok-keyword">func</span> <span class="tok-function">close</span>(_ a<span class="tok-operator">:</span> <span class="tok-type">CGRect</span>, _ b<span class="tok-operator">:</span> <span class="tok-type">CGRect</span>, tol<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span> <span class="tok-operator">=</span> exact<span class="tok-type">Floor</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Bool</span> {
    <span class="tok-function">abs</span>(a<span class="tok-operator">.</span>min<span class="tok-type">X</span> <span class="tok-operator">-</span> b<span class="tok-operator">.</span>min<span class="tok-type">X</span>) <span class="tok-operator">&lt;</span><span class="tok-operator">=</span> tol <span class="tok-operator">&amp;</span><span class="tok-operator">&amp;</span> <span class="tok-function">abs</span>(a<span class="tok-operator">.</span>min<span class="tok-type">Y</span> <span class="tok-operator">-</span> b<span class="tok-operator">.</span>min<span class="tok-type">Y</span>) <span class="tok-operator">&lt;</span><span class="tok-operator">=</span> tol <span class="tok-operator">&amp;</span><span class="tok-operator">&amp;</span>
        <span class="tok-function">abs</span>(a<span class="tok-operator">.</span>width <span class="tok-operator">-</span> b<span class="tok-operator">.</span>width) <span class="tok-operator">&lt;</span><span class="tok-operator">=</span> tol <span class="tok-operator">&amp;</span><span class="tok-operator">&amp;</span> <span class="tok-function">abs</span>(a<span class="tok-operator">.</span>height <span class="tok-operator">-</span> b<span class="tok-operator">.</span>height) <span class="tok-operator">&lt;</span><span class="tok-operator">=</span> tol
}</code></pre>
<p>When a layout test fails, the rule is to find why the behavior differs and fix the engine,
never to widen <code>exactFloor</code> until the failure disappears. A tolerance you are allowed to
relax is a wish, not a measurement.</p>
<h2>Measuring animation: hold the spring against SwiftUI’s Spring</h2>
<p>Animation is the most quantitative area, because motion is numbers over time. A spring is a
damped harmonic oscillator. Released from rest, its progress curve is</p>
<div class="td-math td-math-display"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 171.94 21.18" fill="currentColor" aria-hidden="true" style="width:17.19em;height:2.12em;vertical-align:-0.81em"><path d="M5.21 10.93C5.21 9.66 4.24 8.67 3.12 8.67C2.34 8.67 1.92 9.11 1.72 9.33L1.72 8.67L0.28 8.78L0.28 9.09C0.99 9.09 1.06 9.15 1.06 9.59L1.06 14.27C1.06 14.72 0.95 14.72 0.28 14.72L0.28 15.03L1.4 15L2.53 15.03L2.53 14.72C1.86 14.72 1.75 14.72 1.75 14.27L1.75 12.59L1.75 12.5C1.8 12.66 2.22 13.2 2.98 13.2C4.17 13.2 5.21 12.22 5.21 10.93ZM4.38 10.93C4.38 12.14 3.68 12.98 2.94 12.98C2.54 12.98 2.16 12.78 1.89 12.37C1.75 12.16 1.75 12.15 1.75 11.95L1.75 9.72C2.04 9.21 2.53 8.92 3.04 8.92C3.77 8.92 4.38 9.8 4.38 10.93Z"/><path d="M8.88 15.47C8.88 15.44 8.86 15.41 8.84 15.39C7.8 14.61 7.11 12.61 7.11 11.01L7.11 10.17C7.11 8.57 7.8 6.57 8.84 5.79C8.86 5.77 8.88 5.74 8.88 5.71C8.88 5.66 8.83 5.61 8.78 5.61C8.76 5.61 8.74 5.62 8.72 5.63C7.62 6.46 6.57 8.46 6.57 10.17L6.57 11.01C6.57 12.72 7.62 14.72 8.72 15.55C8.74 15.56 8.76 15.57 8.78 15.57C8.83 15.57 8.88 15.52 8.88 15.47Z"/><path d="M12.77 11.85L12.77 11.28L12.52 11.28L12.52 11.83C12.52 12.57 12.22 12.95 11.85 12.95C11.18 12.95 11.18 12.04 11.18 11.87L11.18 9.09L12.61 9.09L12.61 8.78L11.18 8.78L11.18 6.94L10.93 6.94C10.92 7.76 10.62 8.83 9.64 8.87L9.64 9.09L10.49 9.09L10.49 11.85C10.49 13.08 11.42 13.2 11.78 13.2C12.49 13.2 12.77 12.49 12.77 11.85Z"/><path d="M16.22 11.01L16.22 10.17C16.22 8.46 15.17 6.46 14.07 5.63C14.05 5.62 14.03 5.61 14.01 5.61C13.96 5.61 13.91 5.66 13.91 5.71C13.91 5.74 13.93 5.77 13.95 5.79C14.99 6.57 15.68 8.57 15.68 10.17L15.68 11.01C15.68 12.61 14.99 14.61 13.95 15.39C13.93 15.41 13.91 15.44 13.91 15.47C13.91 15.52 13.96 15.57 14.01 15.57C14.03 15.57 14.05 15.56 14.07 15.55C15.17 14.72 16.22 12.72 16.22 11.01Z"/><path d="M27.23 9.62C27.23 9.51 27.14 9.42 27.03 9.42L20.77 9.42C20.66 9.42 20.57 9.51 20.57 9.62C20.57 9.73 20.66 9.82 20.77 9.82L27.03 9.82C27.14 9.82 27.23 9.73 27.23 9.62ZM27.23 11.56C27.23 11.45 27.14 11.36 27.03 11.36L20.77 11.36C20.66 11.36 20.57 11.45 20.57 11.56C20.57 11.67 20.66 11.76 20.77 11.76L27.03 11.76C27.14 11.76 27.23 11.67 27.23 11.56Z"/><path d="M34.76 13.09L34.76 12.78L34.44 12.78C33.54 12.78 33.51 12.67 33.51 12.3L33.51 6.69C33.51 6.45 33.51 6.43 33.28 6.43C32.66 7.07 31.78 7.07 31.46 7.07L31.46 7.38C31.66 7.38 32.25 7.38 32.77 7.12L32.77 12.3C32.77 12.66 32.74 12.78 31.84 12.78L31.52 12.78L31.52 13.09C31.87 13.06 32.74 13.06 33.14 13.06C33.54 13.06 34.41 13.06 34.76 13.09Z"/><path d="M40.55 11.22L40.55 10.64L37.9 10.64L37.9 11.22Z"/><path d="M47.49 11.9C47.49 11.8 47.41 11.78 47.36 11.78C47.27 11.78 47.25 11.84 47.23 11.92C46.88 12.95 45.98 12.95 45.88 12.95C45.38 12.95 44.98 12.65 44.75 12.28C44.45 11.8 44.45 11.14 44.45 10.78L47.24 10.78C47.46 10.78 47.49 10.78 47.49 10.57C47.49 9.58 46.95 8.61 45.7 8.61C44.54 8.61 43.62 9.64 43.62 10.89C43.62 12.23 44.67 13.2 45.82 13.2C47.04 13.2 47.49 12.09 47.49 11.9ZM46.83 10.57L44.46 10.57C44.52 9.08 45.36 8.83 45.7 8.83C46.73 8.83 46.83 10.18 46.83 10.57Z"/><path d="M50.27 8.15L50.27 7.75L48.42 7.75L48.42 8.15Z"/><path d="M54.06 10.05C53.99 9.78 53.82 9.64 53.75 9.58C53.6 9.45 53.46 9.41 53.01 9.27C52.4 9.08 52.28 9.04 52.08 8.9C51.71 8.63 51.62 8.23 51.58 8.1C51.32 7.01 51.86 5.79 52.47 5.41C52.63 5.54 52.79 5.54 52.93 5.54C53.11 5.54 53.56 5.54 53.5 5.32C53.46 5.14 53.17 5.13 52.89 5.13C52.81 5.13 52.62 5.13 52.46 5.2C52.41 5.12 52.39 5.08 52.34 4.93C52.32 4.84 52.32 4.67 52.32 4.67C52.3 4.62 52.26 4.58 52.21 4.58C52.09 4.58 52.16 4.91 52.17 4.93C52.2 5.05 52.25 5.17 52.34 5.28C51.69 5.65 50.91 6.94 51.25 8.29C51.5 9.28 52.18 9.49 52.73 9.66C52.96 9.74 52.97 9.74 53.19 9.81C53.35 9.85 53.66 9.95 53.74 10.28C53.79 10.47 53.73 10.74 53.47 10.74C53.29 10.74 53.08 10.66 52.9 10.53C52.84 10.49 52.83 10.48 52.8 10.48C52.76 10.48 52.74 10.51 52.75 10.56C52.77 10.63 53.14 10.9 53.51 10.9C53.94 10.9 54.16 10.45 54.06 10.05ZM53.32 5.33C53.27 5.35 53.21 5.38 52.9 5.38C52.75 5.38 52.7 5.38 52.62 5.33C52.71 5.28 52.83 5.28 52.93 5.28C53.16 5.28 53.18 5.29 53.32 5.33Z"/><path d="M58.55 7.79C58.56 7.49 58.55 7.14 58.48 6.86C58.44 6.68 58.36 6.52 58.24 6.43C58.18 6.39 58.13 6.37 58.06 6.37C57.98 6.37 57.9 6.41 57.85 6.48C57.8 6.55 57.78 6.63 57.8 6.7C57.82 6.77 57.86 6.83 57.92 6.88C58.13 7.03 58.28 7.25 58.34 7.5C58.36 7.58 58.38 7.67 58.38 7.75C58.38 8.39 58.13 9.04 57.58 9.04C57.19 9.04 56.89 8.77 56.73 8.41C56.78 8.21 56.8 8 56.79 7.79C56.79 7.73 56.79 7.66 56.78 7.61C56.75 7.5 56.69 7.43 56.59 7.43C56.46 7.43 56.44 7.6 56.44 7.75C56.44 7.97 56.46 8.18 56.51 8.38C56.37 8.76 56.1 9.04 55.72 9.04C55.29 9.04 55.02 8.69 54.91 8.24C54.88 8.1 54.86 7.94 54.85 7.79C54.85 7.37 55 6.98 55.18 6.61C55.19 6.58 55.2 6.54 55.19 6.52C55.18 6.47 55.14 6.44 55.1 6.42C55.08 6.4 55.06 6.4 55.04 6.4C55 6.4 54.96 6.42 54.93 6.47C54.74 6.87 54.68 7.31 54.68 7.75C54.68 8.02 54.7 8.29 54.77 8.54C54.91 9.11 55.22 9.54 55.75 9.54C56.19 9.54 56.48 9.23 56.64 8.8C56.82 9.23 57.15 9.54 57.62 9.54C58.34 9.54 58.56 8.64 58.55 7.79Z"/><path d="M61.51 9.62C61.51 9.23 61.49 8.84 61.32 8.48C61.09 8.01 60.69 7.93 60.49 7.93C60.19 7.93 59.83 8.06 59.63 8.51C59.48 8.85 59.45 9.23 59.45 9.62C59.45 9.99 59.47 10.43 59.67 10.8C59.88 11.2 60.24 11.3 60.48 11.3C60.74 11.3 61.12 11.2 61.33 10.73C61.49 10.39 61.51 10.01 61.51 9.62ZM61.11 9.56C61.11 9.93 61.11 10.27 61.05 10.58C60.98 11.04 60.7 11.19 60.48 11.19C60.29 11.19 60 11.07 59.91 10.6C59.86 10.3 59.86 9.85 59.86 9.56C59.86 9.25 59.86 8.93 59.9 8.66C59.99 8.08 60.36 8.04 60.48 8.04C60.64 8.04 60.97 8.12 61.06 8.61C61.11 8.88 61.11 9.26 61.11 9.56Z"/><path d="M64.03 8.59L64.03 8.2L63.86 8.2L63.86 8.58C63.86 9.1 63.65 9.36 63.39 9.36C62.92 9.36 62.92 8.73 62.92 8.61L62.92 6.66L63.92 6.66L63.92 6.45L62.92 6.45L62.92 5.16L62.75 5.16C62.74 5.73 62.53 6.48 61.84 6.51L61.84 6.66L62.44 6.66L62.44 8.59C62.44 9.46 63.09 9.54 63.34 9.54C63.84 9.54 64.03 9.04 64.03 8.59Z"/><path d="M66.99 15.39C66.99 15.28 66.9 15.19 66.79 15.19L65.97 15.19L65.97 5.99L66.79 5.99C66.9 5.99 66.99 5.9 66.99 5.79C66.99 5.68 66.9 5.59 66.79 5.59L65.57 5.59L65.57 15.59L66.79 15.59C66.9 15.59 66.99 15.5 66.99 15.39Z"/><path d="M71.36 11.9C71.36 11.8 71.26 11.8 71.23 11.8C71.14 11.8 71.12 11.84 71.1 11.9C70.81 12.83 70.16 12.95 69.79 12.95C69.26 12.95 68.38 12.52 68.38 10.91C68.38 9.28 69.2 8.86 69.73 8.86C69.82 8.86 70.45 8.87 70.8 9.23C70.39 9.26 70.33 9.56 70.33 9.69C70.33 9.95 70.51 10.15 70.79 10.15C71.05 10.15 71.25 9.98 71.25 9.68C71.25 9 70.49 8.61 69.72 8.61C68.47 8.61 67.55 9.69 67.55 10.93C67.55 12.21 68.54 13.2 69.7 13.2C71.04 13.2 71.36 12 71.36 11.9Z"/><path d="M76.36 10.95C76.36 9.67 75.36 8.61 74.15 8.61C72.9 8.61 71.93 9.7 71.93 10.95C71.93 12.24 72.97 13.2 74.14 13.2C75.35 13.2 76.36 12.22 76.36 10.95ZM75.53 10.87C75.53 11.23 75.53 11.77 75.31 12.21C75.09 12.66 74.65 12.95 74.15 12.95C73.72 12.95 73.28 12.74 73.01 12.28C72.76 11.84 72.76 11.23 72.76 10.87C72.76 10.48 72.76 9.94 73 9.5C73.27 9.04 73.74 8.83 74.14 8.83C74.58 8.83 75.01 9.05 75.27 9.48C75.53 9.91 75.53 10.49 75.53 10.87Z"/><path d="M80.25 11.81C80.25 11.28 79.95 10.98 79.83 10.86C79.5 10.54 79.11 10.46 78.69 10.38C78.13 10.27 77.46 10.14 77.46 9.56C77.46 9.21 77.72 8.8 78.58 8.8C79.68 8.8 79.73 9.7 79.75 10.01C79.76 10.1 79.87 10.1 79.87 10.1C80 10.1 80 10.05 80 9.86L80 8.85C80 8.68 80 8.61 79.89 8.61C79.84 8.61 79.82 8.61 79.69 8.73C79.66 8.77 79.56 8.86 79.52 8.89C79.14 8.61 78.73 8.61 78.58 8.61C77.36 8.61 76.98 9.28 76.98 9.84C76.98 10.19 77.14 10.47 77.41 10.69C77.73 10.95 78.01 11.01 78.73 11.15C78.95 11.19 79.77 11.35 79.77 12.07C79.77 12.58 79.42 12.98 78.64 12.98C77.8 12.98 77.44 12.41 77.25 11.56C77.22 11.43 77.21 11.39 77.11 11.39C76.98 11.39 76.98 11.46 76.98 11.64L76.98 12.96C76.98 13.13 76.98 13.2 77.09 13.2C77.14 13.2 77.15 13.19 77.34 13C77.36 12.98 77.36 12.96 77.54 12.77C77.98 13.19 78.43 13.2 78.64 13.2C79.79 13.2 80.25 12.53 80.25 11.81Z"/><path d="M83.91 15.47C83.91 15.44 83.89 15.41 83.87 15.39C82.83 14.61 82.14 12.61 82.14 11.01L82.14 10.17C82.14 8.57 82.83 6.57 83.87 5.79C83.89 5.77 83.91 5.74 83.91 5.71C83.91 5.66 83.86 5.61 83.81 5.61C83.79 5.61 83.77 5.62 83.75 5.63C82.65 6.46 81.6 8.46 81.6 10.17L81.6 11.01C81.6 12.72 82.65 14.72 83.75 15.55C83.77 15.56 83.79 15.57 83.81 15.57C83.86 15.57 83.91 15.52 83.91 15.47Z"/><path d="M90.44 10.7C90.45 10.27 90.44 9.77 90.34 9.37C90.28 9.11 90.17 8.89 89.99 8.76C89.91 8.7 89.83 8.67 89.74 8.67C89.62 8.67 89.5 8.73 89.43 8.83C89.36 8.93 89.34 9.04 89.37 9.15C89.39 9.25 89.45 9.33 89.54 9.4C89.84 9.62 90.05 9.93 90.14 10.28C90.17 10.4 90.19 10.53 90.19 10.65C90.19 11.56 89.84 12.48 89.05 12.48C88.49 12.48 88.06 12.1 87.84 11.58C87.9 11.3 87.93 11 87.92 10.7C87.92 10.61 87.92 10.52 87.9 10.44C87.86 10.29 87.78 10.18 87.64 10.18C87.45 10.18 87.42 10.43 87.42 10.65C87.42 10.96 87.45 11.26 87.52 11.55C87.32 12.09 86.94 12.48 86.39 12.48C85.78 12.48 85.39 11.98 85.24 11.35C85.19 11.15 85.16 10.92 85.15 10.7C85.15 10.1 85.37 9.54 85.62 9.01C85.64 8.97 85.65 8.92 85.64 8.88C85.62 8.82 85.57 8.77 85.51 8.74C85.48 8.72 85.45 8.72 85.42 8.72C85.36 8.72 85.3 8.75 85.26 8.81C84.99 9.38 84.9 10.02 84.9 10.65C84.9 11.03 84.94 11.42 85.03 11.77C85.23 12.58 85.68 13.2 86.44 13.2C87.07 13.2 87.48 12.76 87.7 12.14C87.97 12.76 88.43 13.2 89.1 13.2C90.14 13.2 90.45 11.91 90.44 10.7Z"/><path d="M95.14 15.56L95.14 15.35C94.65 15.35 94.6 15.3 94.6 14.95L94.6 10.7L93.59 10.78L93.59 11C94.08 11 94.13 11.05 94.13 11.39L94.13 12.9C93.93 12.65 93.63 12.47 93.25 12.47C92.43 12.47 91.69 13.15 91.69 14.06C91.69 14.95 92.38 15.64 93.18 15.64C93.62 15.64 93.94 15.4 94.11 15.18L94.11 15.64ZM94.11 14.74C94.11 14.86 94.11 14.88 94.04 15C93.83 15.33 93.51 15.49 93.21 15.49C92.9 15.49 92.64 15.3 92.48 15.04C92.29 14.75 92.27 14.35 92.27 14.06C92.27 13.81 92.29 13.39 92.49 13.07C92.64 12.85 92.9 12.62 93.28 12.62C93.53 12.62 93.82 12.73 94.04 13.04C94.11 13.16 94.11 13.18 94.11 13.3Z"/><path d="M98.67 11.85L98.67 11.28L98.42 11.28L98.42 11.83C98.42 12.57 98.12 12.95 97.75 12.95C97.08 12.95 97.08 12.04 97.08 11.87L97.08 9.09L98.51 9.09L98.51 8.78L97.08 8.78L97.08 6.94L96.83 6.94C96.82 7.76 96.52 8.83 95.54 8.87L95.54 9.09L96.39 9.09L96.39 11.85C96.39 13.08 97.32 13.2 97.68 13.2C98.39 13.2 98.67 12.49 98.67 11.85Z"/><path d="M102.12 11.01L102.12 10.17C102.12 8.46 101.07 6.46 99.97 5.63C99.95 5.62 99.93 5.61 99.91 5.61C99.86 5.61 99.81 5.66 99.81 5.71C99.81 5.74 99.83 5.77 99.85 5.79C100.89 6.57 101.58 8.57 101.58 10.17L101.58 11.01C101.58 12.61 100.89 14.61 99.85 15.39C99.83 15.41 99.81 15.44 99.81 15.47C99.81 15.52 99.86 15.57 99.91 15.57C99.93 15.57 99.95 15.56 99.97 15.55C101.07 14.72 102.12 12.72 102.12 11.01Z"/><path d="M112.57 10.59C112.57 10.48 112.48 10.39 112.37 10.39L109.44 10.39L109.44 7.46C109.44 7.35 109.35 7.26 109.24 7.26C109.13 7.26 109.04 7.35 109.04 7.46L109.04 10.39L106.11 10.39C106 10.39 105.91 10.48 105.91 10.59C105.91 10.7 106 10.79 106.11 10.79L109.04 10.79L109.04 13.72C109.04 13.83 109.13 13.92 109.24 13.92C109.35 13.92 109.44 13.83 109.44 13.72L109.44 10.79L112.37 10.79C112.48 10.79 112.57 10.7 112.57 10.59Z"/><rect x="115.35" y="10.39" width="17.33" height="0.4"/><path d="M121.52 6.59C121.44 6.28 121.24 6.11 121.16 6.04C120.99 5.89 120.81 5.84 120.29 5.67C119.57 5.45 119.44 5.41 119.2 5.24C118.77 4.93 118.66 4.46 118.62 4.3C118.3 3.03 118.94 1.6 119.66 1.16C119.85 1.3 120.03 1.3 120.2 1.3C120.4 1.3 120.93 1.3 120.86 1.05C120.81 0.84 120.48 0.83 120.15 0.83C120.06 0.83 119.84 0.83 119.65 0.91C119.58 0.81 119.56 0.77 119.51 0.6C119.48 0.48 119.48 0.3 119.48 0.3C119.46 0.23 119.41 0.19 119.35 0.19C119.21 0.19 119.3 0.57 119.3 0.59C119.34 0.73 119.4 0.88 119.5 1C118.75 1.43 117.83 2.94 118.22 4.53C118.52 5.69 119.32 5.94 119.96 6.13C120.23 6.22 120.25 6.22 120.5 6.31C120.69 6.36 121.05 6.48 121.15 6.86C121.21 7.08 121.13 7.4 120.83 7.4C120.62 7.4 120.37 7.31 120.16 7.16C120.09 7.11 120.08 7.1 120.04 7.1C120 7.1 119.97 7.13 119.98 7.19C120.01 7.27 120.44 7.58 120.87 7.58C121.38 7.58 121.63 7.06 121.52 6.59ZM120.65 1.06C120.59 1.08 120.52 1.12 120.16 1.12C119.98 1.12 119.93 1.12 119.83 1.07C119.94 1.01 120.08 1.01 120.19 1.01C120.46 1.01 120.49 1.02 120.65 1.06Z"/><path d="M126.78 3.94C126.79 3.59 126.78 3.18 126.7 2.85C126.65 2.64 126.56 2.46 126.41 2.35C126.35 2.3 126.28 2.28 126.21 2.28C126.11 2.28 126.01 2.33 125.95 2.41C125.9 2.49 125.88 2.58 125.91 2.67C125.92 2.76 125.97 2.82 126.04 2.88C126.29 3.06 126.46 3.31 126.54 3.6C126.56 3.7 126.58 3.8 126.58 3.9C126.58 4.65 126.29 5.4 125.64 5.4C125.18 5.4 124.83 5.09 124.65 4.67C124.7 4.44 124.72 4.19 124.72 3.94C124.72 3.87 124.72 3.8 124.7 3.73C124.67 3.61 124.6 3.52 124.49 3.52C124.33 3.52 124.31 3.72 124.31 3.9C124.31 4.16 124.33 4.4 124.39 4.64C124.22 5.08 123.91 5.4 123.46 5.4C122.96 5.4 122.64 4.99 122.52 4.48C122.48 4.31 122.45 4.12 122.44 3.94C122.44 3.45 122.63 2.99 122.83 2.56C122.85 2.53 122.85 2.48 122.85 2.45C122.83 2.4 122.79 2.36 122.74 2.34C122.72 2.32 122.69 2.32 122.67 2.32C122.62 2.32 122.57 2.35 122.54 2.39C122.31 2.86 122.24 3.39 122.24 3.9C122.24 4.21 122.27 4.53 122.35 4.82C122.51 5.49 122.88 5.99 123.5 5.99C124.02 5.99 124.36 5.63 124.54 5.12C124.76 5.63 125.13 5.99 125.68 5.99C126.54 5.99 126.79 4.94 126.78 3.94Z"/><path d="M130.25 6.09C130.25 5.63 130.22 5.17 130.02 4.75C129.76 4.2 129.29 4.11 129.05 4.11C128.7 4.11 128.28 4.26 128.05 4.79C127.86 5.19 127.83 5.63 127.83 6.09C127.83 6.52 127.86 7.04 128.09 7.48C128.34 7.94 128.76 8.06 129.04 8.06C129.35 8.06 129.79 7.94 130.04 7.39C130.22 6.99 130.25 6.55 130.25 6.09ZM129.77 6.02C129.77 6.45 129.77 6.84 129.71 7.21C129.63 7.76 129.3 7.93 129.04 7.93C128.82 7.93 128.48 7.79 128.37 7.23C128.31 6.89 128.31 6.36 128.31 6.02C128.31 5.66 128.31 5.28 128.36 4.97C128.47 4.28 128.9 4.23 129.04 4.23C129.23 4.23 129.61 4.34 129.72 4.9C129.77 5.23 129.77 5.66 129.77 6.02Z"/><path d="M124.45 15.94C124.46 15.58 124.45 15.17 124.37 14.85C124.32 14.63 124.23 14.45 124.08 14.35C124.01 14.3 123.95 14.27 123.87 14.27C123.78 14.27 123.68 14.32 123.62 14.4C123.56 14.48 123.55 14.58 123.57 14.67C123.59 14.75 123.64 14.81 123.71 14.87C123.96 15.05 124.13 15.3 124.2 15.59C124.23 15.69 124.24 15.8 124.24 15.9C124.24 16.64 123.96 17.4 123.31 17.4C122.85 17.4 122.5 17.08 122.32 16.66C122.37 16.43 122.39 16.18 122.38 15.94C122.38 15.86 122.38 15.79 122.37 15.72C122.33 15.6 122.27 15.51 122.15 15.51C122 15.51 121.97 15.71 121.97 15.9C121.97 16.15 122 16.4 122.05 16.63C121.89 17.08 121.58 17.4 121.13 17.4C120.63 17.4 120.31 16.99 120.18 16.47C120.14 16.31 120.12 16.12 120.11 15.94C120.11 15.44 120.29 14.99 120.5 14.55C120.51 14.52 120.52 14.48 120.51 14.44C120.5 14.39 120.46 14.35 120.41 14.33C120.38 14.31 120.36 14.31 120.33 14.31C120.28 14.31 120.23 14.34 120.2 14.39C119.98 14.85 119.91 15.38 119.91 15.9C119.91 16.21 119.94 16.53 120.01 16.81C120.18 17.48 120.55 17.99 121.17 17.99C121.69 17.99 122.02 17.63 122.2 17.12C122.42 17.63 122.8 17.99 123.35 17.99C124.2 17.99 124.46 16.93 124.45 15.94Z"/><path d="M128.3 19.92L128.3 19.74C127.9 19.74 127.85 19.7 127.85 19.42L127.85 15.94L127.03 16L127.03 16.18C127.43 16.18 127.48 16.22 127.48 16.5L127.48 17.74C127.31 17.53 127.06 17.38 126.75 17.38C126.07 17.38 125.47 17.95 125.47 18.69C125.47 19.42 126.03 19.98 126.69 19.98C127.06 19.98 127.31 19.79 127.46 19.61L127.46 19.98ZM127.46 19.24C127.46 19.35 127.46 19.36 127.4 19.46C127.22 19.73 126.96 19.86 126.72 19.86C126.46 19.86 126.25 19.71 126.12 19.49C125.97 19.26 125.95 18.93 125.95 18.69C125.95 18.48 125.96 18.14 126.13 17.88C126.25 17.7 126.47 17.51 126.78 17.51C126.98 17.51 127.22 17.6 127.4 17.86C127.46 17.95 127.46 17.96 127.46 18.07Z"/><path d="M137.95 11.81C137.95 11.28 137.65 10.98 137.53 10.86C137.2 10.54 136.81 10.46 136.39 10.38C135.83 10.27 135.16 10.14 135.16 9.56C135.16 9.21 135.42 8.8 136.28 8.8C137.38 8.8 137.43 9.7 137.45 10.01C137.46 10.1 137.57 10.1 137.57 10.1C137.7 10.1 137.7 10.05 137.7 9.86L137.7 8.85C137.7 8.68 137.7 8.61 137.59 8.61C137.54 8.61 137.52 8.61 137.39 8.73C137.36 8.77 137.26 8.86 137.22 8.89C136.84 8.61 136.43 8.61 136.28 8.61C135.06 8.61 134.68 9.28 134.68 9.84C134.68 10.19 134.84 10.47 135.11 10.69C135.43 10.95 135.71 11.01 136.43 11.15C136.65 11.19 137.47 11.35 137.47 12.07C137.47 12.58 137.12 12.98 136.34 12.98C135.5 12.98 135.14 12.41 134.95 11.56C134.92 11.43 134.91 11.39 134.81 11.39C134.68 11.39 134.68 11.46 134.68 11.64L134.68 12.96C134.68 13.13 134.68 13.2 134.79 13.2C134.84 13.2 134.85 13.19 135.04 13C135.06 12.98 135.06 12.96 135.24 12.77C135.68 13.19 136.13 13.2 136.34 13.2C137.49 13.2 137.95 12.53 137.95 11.81Z"/><path d="M140.76 13.09L140.76 12.78C140.1 12.78 140.06 12.73 140.06 12.34L140.06 8.67L138.66 8.78L138.66 9.09C139.31 9.09 139.4 9.15 139.4 9.64L139.4 12.33C139.4 12.78 139.29 12.78 138.62 12.78L138.62 13.09L139.72 13.06C140.07 13.06 140.42 13.08 140.76 13.09ZM140.21 7.05C140.21 6.78 139.98 6.52 139.68 6.52C139.34 6.52 139.14 6.8 139.14 7.05C139.14 7.32 139.37 7.58 139.67 7.58C140.01 7.58 140.21 7.3 140.21 7.05Z"/><path d="M146.42 13.09L146.42 12.78C145.9 12.78 145.65 12.78 145.64 12.48L145.64 10.57C145.64 9.71 145.64 9.4 145.33 9.04C145.19 8.87 144.86 8.67 144.28 8.67C143.55 8.67 143.08 9.1 142.8 9.72L142.8 8.67L141.39 8.78L141.39 9.09C142.09 9.09 142.17 9.16 142.17 9.65L142.17 12.33C142.17 12.78 142.06 12.78 141.39 12.78L141.39 13.09L142.52 13.06L143.64 13.09L143.64 12.78C142.97 12.78 142.86 12.78 142.86 12.33L142.86 10.49C142.86 9.45 143.57 8.89 144.21 8.89C144.84 8.89 144.95 9.43 144.95 10L144.95 12.33C144.95 12.78 144.84 12.78 144.17 12.78L144.17 13.09L145.3 13.06Z"/><path d="M149.95 15.47C149.95 15.44 149.93 15.41 149.91 15.39C148.87 14.61 148.18 12.61 148.18 11.01L148.18 10.17C148.18 8.57 148.87 6.57 149.91 5.79C149.93 5.77 149.95 5.74 149.95 5.71C149.95 5.66 149.9 5.61 149.85 5.61C149.83 5.61 149.81 5.62 149.79 5.63C148.69 6.46 147.64 8.46 147.64 10.17L147.64 11.01C147.64 12.72 148.69 14.72 149.79 15.55C149.81 15.56 149.83 15.57 149.85 15.57C149.9 15.57 149.95 15.52 149.95 15.47Z"/><path d="M156.48 10.7C156.49 10.27 156.48 9.77 156.38 9.37C156.32 9.11 156.21 8.89 156.03 8.76C155.95 8.7 155.87 8.67 155.78 8.67C155.66 8.67 155.54 8.73 155.47 8.83C155.4 8.93 155.38 9.04 155.41 9.15C155.43 9.25 155.49 9.33 155.58 9.4C155.88 9.62 156.09 9.93 156.18 10.28C156.21 10.4 156.23 10.53 156.23 10.65C156.23 11.56 155.88 12.48 155.09 12.48C154.53 12.48 154.1 12.1 153.88 11.58C153.94 11.3 153.97 11 153.96 10.7C153.96 10.61 153.96 10.52 153.94 10.44C153.9 10.29 153.82 10.18 153.68 10.18C153.49 10.18 153.46 10.43 153.46 10.65C153.46 10.96 153.49 11.26 153.56 11.55C153.36 12.09 152.98 12.48 152.43 12.48C151.82 12.48 151.43 11.98 151.28 11.35C151.23 11.15 151.2 10.92 151.19 10.7C151.19 10.1 151.41 9.54 151.66 9.01C151.68 8.97 151.69 8.92 151.68 8.88C151.66 8.82 151.61 8.77 151.55 8.74C151.52 8.72 151.49 8.72 151.46 8.72C151.4 8.72 151.34 8.75 151.3 8.81C151.03 9.38 150.94 10.02 150.94 10.65C150.94 11.03 150.98 11.42 151.07 11.77C151.27 12.58 151.72 13.2 152.48 13.2C153.11 13.2 153.52 12.76 153.74 12.14C154.01 12.76 154.47 13.2 155.14 13.2C156.18 13.2 156.49 11.91 156.48 10.7Z"/><path d="M161.18 15.56L161.18 15.35C160.69 15.35 160.63 15.3 160.63 14.95L160.63 10.7L159.62 10.78L159.62 11C160.11 11 160.17 11.05 160.17 11.39L160.17 12.9C159.97 12.65 159.66 12.47 159.29 12.47C158.46 12.47 157.73 13.15 157.73 14.06C157.73 14.95 158.41 15.64 159.21 15.64C159.66 15.64 159.97 15.4 160.15 15.18L160.15 15.64ZM160.15 14.74C160.15 14.86 160.15 14.88 160.07 15C159.86 15.33 159.55 15.49 159.24 15.49C158.93 15.49 158.68 15.3 158.51 15.04C158.33 14.75 158.31 14.35 158.31 14.06C158.31 13.81 158.32 13.39 158.52 13.07C158.67 12.85 158.94 12.62 159.31 12.62C159.56 12.62 159.85 12.73 160.07 13.04C160.15 13.16 160.15 13.18 160.15 13.3Z"/><path d="M164.7 11.85L164.7 11.28L164.45 11.28L164.45 11.83C164.45 12.57 164.15 12.95 163.78 12.95C163.11 12.95 163.11 12.04 163.11 11.87L163.11 9.09L164.54 9.09L164.54 8.78L163.11 8.78L163.11 6.94L162.86 6.94C162.85 7.76 162.55 8.83 161.57 8.87L161.57 9.09L162.42 9.09L162.42 11.85C162.42 13.08 163.35 13.2 163.71 13.2C164.42 13.2 164.7 12.49 164.7 11.85Z"/><path d="M168.15 11.01L168.15 10.17C168.15 8.46 167.1 6.46 166 5.63C165.98 5.62 165.96 5.61 165.94 5.61C165.89 5.61 165.84 5.66 165.84 5.71C165.84 5.74 165.86 5.77 165.88 5.79C166.92 6.57 167.61 8.57 167.61 10.17L167.61 11.01C167.61 12.61 166.92 14.61 165.88 15.39C165.86 15.41 165.84 15.44 165.84 15.47C165.84 15.52 165.89 15.57 165.94 15.57C165.96 15.57 165.98 15.56 166 15.55C167.1 14.72 168.15 12.72 168.15 11.01Z"/><path d="M170.8 15.59L170.8 5.59L169.58 5.59C169.47 5.59 169.38 5.68 169.38 5.79C169.38 5.9 169.47 5.99 169.58 5.99L170.4 5.99L170.4 15.19L169.58 15.19C169.47 15.19 169.38 15.28 169.38 15.39C169.38 15.5 169.47 15.59 169.58 15.59Z"/></svg><math class="td-math-a11y" xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi>p</mi><mtext>(</mtext><mi>t</mi><mtext>)</mtext><mtext> </mtext><mtext>=</mtext><mtext> </mtext><mn>1</mn><mtext> </mtext><mtext>-</mtext><mtext> </mtext><msup><mrow><mi>e</mi></mrow><mrow><mrow><mtext>-</mtext><mo>ζ</mo><mtext> </mtext><msub><mrow><mo>ω</mo></mrow><mrow><mn>0</mn></mrow></msub><mtext> </mtext><mi>t</mi></mrow></mrow></msup><mrow><mtext>[</mtext><mrow><mo>cos</mo><mtext>(</mtext><msub><mrow><mo>ω</mo></mrow><mrow><mi>d</mi></mrow></msub><mtext> </mtext><mi>t</mi><mtext>)</mtext><mtext> </mtext><mtext>+</mtext><mtext> </mtext><mfrac><mrow><mrow><mo>ζ</mo><mtext> </mtext><msub><mrow><mo>ω</mo></mrow><mrow><mn>0</mn></mrow></msub></mrow></mrow><mrow><msub><mrow><mo>ω</mo></mrow><mrow><mi>d</mi></mrow></msub></mrow></mfrac><mtext> </mtext><mo>sin</mo><mtext>(</mtext><msub><mrow><mo>ω</mo></mrow><mrow><mi>d</mi></mrow></msub><mtext> </mtext><mi>t</mi><mtext>)</mtext></mrow><mtext>]</mtext></mrow></mrow></math></div>
<p>which starts at 0, sweeps past 1, and settles back. We sample the engine’s spring and
SwiftUI’s own <code>Spring</code> at the same times and assert they agree across all three damping
regimes.</p>
<pre><code class="language-swift"><span class="tok-attribute">@available</span>(mac<span class="tok-type">OS</span> <span class="tok-number">14</span>, i<span class="tok-type">OS</span> <span class="tok-number">17</span>, <span class="tok-operator">*</span>)
<span class="tok-keyword">private</span> <span class="tok-keyword">func</span> <span class="tok-function">assertSpringMatches</span>(
    response<span class="tok-operator">:</span> <span class="tok-type">Double</span>,
    damping<span class="tok-type">Fraction</span><span class="tok-operator">:</span> <span class="tok-type">Double</span>,
    tolerance<span class="tok-operator">:</span> <span class="tok-type">Double</span> <span class="tok-operator">=</span> <span class="tok-number">1</span>e<span class="tok-number">-6</span>
) {
    <span class="tok-keyword">let</span> engine <span class="tok-operator">=</span> <span class="tok-type">PureView</span><span class="tok-operator">.</span><span class="tok-type">Spring</span>(response<span class="tok-operator">:</span> response, damping<span class="tok-type">Fraction</span><span class="tok-operator">:</span> damping<span class="tok-type">Fraction</span>)
    <span class="tok-keyword">let</span> oracle <span class="tok-operator">=</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">Spring</span>(response<span class="tok-operator">:</span> response, damping<span class="tok-type">Ratio</span><span class="tok-operator">:</span> damping<span class="tok-type">Fraction</span>)
    <span class="tok-keyword">let</span> samples <span class="tok-operator">=</span> <span class="tok-number">120</span>
    <span class="tok-keyword">for</span> step <span class="tok-keyword">in</span> <span class="tok-number">0</span> <span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">.</span> samples {
        <span class="tok-keyword">let</span> t <span class="tok-operator">=</span> engine<span class="tok-operator">.</span>settle<span class="tok-type">Duration</span> <span class="tok-operator">*</span> <span class="tok-type">Double</span>(step) <span class="tok-operator">/</span> <span class="tok-type">Double</span>(samples)
        <span class="tok-keyword">let</span> engine<span class="tok-type">Value</span> <span class="tok-operator">=</span> engine<span class="tok-operator">.</span><span class="tok-function">unitStepResponse</span>(at<span class="tok-operator">:</span> t)
        <span class="tok-keyword">let</span> oracle<span class="tok-type">Value</span> <span class="tok-operator">=</span> oracle<span class="tok-operator">.</span><span class="tok-function">value</span>(target<span class="tok-operator">:</span> <span class="tok-number">1.0</span>, initial<span class="tok-type">Velocity</span><span class="tok-operator">:</span> <span class="tok-number">0.0</span>, time<span class="tok-operator">:</span> t)
        <span class="tok-attribute">#expect</span>(
            <span class="tok-function">abs</span>(engine<span class="tok-type">Value</span> <span class="tok-operator">-</span> oracle<span class="tok-type">Value</span>) <span class="tok-operator">&lt;</span><span class="tok-operator">=</span> tolerance,
            <span class="tok-string">"spring(response=\(response), damping=\(dampingFraction)) at t=\(t): "</span> <span class="tok-operator">+</span>
            <span class="tok-string">"engine \(engineValue) vs SwiftUI \(oracleValue)"</span>
        )
    }
}</code></pre>
<p>The assertion is the whole point, in one line:</p>
<div class="td-math td-math-display"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 169.11 25.22" fill="currentColor" aria-hidden="true" style="width:16.91em;height:2.52em;vertical-align:-1.22em"><path d="M14.68 13L14.68 12.44C13.74 12.44 13.29 12.44 13.27 11.9L13.27 8.45C13.27 6.9 13.27 6.34 12.71 5.69C12.46 5.38 11.86 5.02 10.82 5.02C9.3 5.02 8.5 6.1 8.2 6.79C7.94 5.22 6.61 5.02 5.8 5.02C4.48 5.02 3.63 5.8 3.12 6.92L3.12 5.02L0.58 5.22L0.58 5.78C1.84 5.78 1.99 5.9 1.99 6.79L1.99 11.63C1.99 12.44 1.79 12.44 0.58 12.44L0.58 13L2.62 12.95L4.64 13L4.64 12.44C3.43 12.44 3.23 12.44 3.23 11.63L3.23 8.31C3.23 6.43 4.51 5.42 5.67 5.42C6.81 5.42 7.01 6.39 7.01 7.42L7.01 11.63C7.01 12.44 6.81 12.44 5.6 12.44L5.6 13L7.64 12.95L9.66 13L9.66 12.44C8.45 12.44 8.25 12.44 8.25 11.63L8.25 8.31C8.25 6.43 9.53 5.42 10.69 5.42C11.83 5.42 12.03 6.39 12.03 7.42L12.03 11.63C12.03 12.44 11.83 12.44 10.62 12.44L10.62 13L12.66 12.95Z"/><path d="M23.76 11.39L23.76 10.38L23.31 10.38L23.31 11.39C23.31 12.44 22.86 12.55 22.66 12.55C22.06 12.55 21.99 11.74 21.99 11.65L21.99 8.03C21.99 7.28 21.99 6.57 21.34 5.9C20.64 5.2 19.73 4.91 18.87 4.91C17.39 4.91 16.14 5.76 16.14 6.95C16.14 7.49 16.5 7.8 16.97 7.8C17.48 7.8 17.8 7.44 17.8 6.97C17.8 6.75 17.71 6.16 16.88 6.14C17.37 5.51 18.25 5.31 18.83 5.31C19.72 5.31 20.75 6.01 20.75 7.62L20.75 8.29C19.83 8.34 18.56 8.4 17.42 8.94C16.07 9.55 15.62 10.49 15.62 11.28C15.62 12.75 17.37 13.2 18.51 13.2C19.7 13.2 20.53 12.48 20.87 11.63C20.94 12.35 21.43 13.11 22.28 13.11C22.66 13.11 23.76 12.86 23.76 11.39ZM20.75 10.47C20.75 12.19 19.45 12.8 18.63 12.8C17.75 12.8 17.01 12.17 17.01 11.27C17.01 10.27 17.77 8.77 20.75 8.67Z"/><path d="M33.38 13L33.38 12.44C32.41 12.44 32.08 12.4 31.67 11.88L29.25 8.76C29.79 8.07 30.48 7.19 30.91 6.72C31.47 6.07 32.21 5.8 33.06 5.78L33.06 5.22C32.59 5.25 32.05 5.27 31.58 5.27C31.04 5.27 30.08 5.24 29.85 5.22L29.85 5.78C30.23 5.81 30.37 6.05 30.37 6.34C30.37 6.63 30.19 6.86 30.1 6.97L28.98 8.38L27.57 6.55C27.41 6.37 27.41 6.34 27.41 6.23C27.41 5.96 27.68 5.8 28.04 5.78L28.04 5.22L26.09 5.27C25.71 5.27 24.86 5.25 24.38 5.22L24.38 5.78C25.64 5.78 25.66 5.8 26.51 6.88L28.29 9.21C27.44 10.29 27.44 10.33 26.6 11.36C25.73 12.4 24.66 12.44 24.28 12.44L24.28 13C24.75 12.96 25.31 12.95 25.78 12.95L27.5 13L27.5 12.44C27.1 12.39 26.98 12.15 26.98 11.88C26.98 11.48 27.5 10.89 28.6 9.59L29.97 11.39C30.12 11.59 30.35 11.88 30.35 11.99C30.35 12.15 30.19 12.42 29.7 12.44L29.7 13L31.65 12.95C32.14 12.95 32.84 12.96 33.38 13Z"/><path d="M17.76 22.81L17.76 22.42L17.59 22.42L17.59 22.8C17.59 23.32 17.38 23.58 17.12 23.58C16.65 23.58 16.65 22.95 16.65 22.83L16.65 20.88L17.65 20.88L17.65 20.67L16.65 20.67L16.65 19.38L16.48 19.38C16.47 19.95 16.26 20.7 15.57 20.73L15.57 20.88L16.17 20.88L16.17 22.81C16.17 23.68 16.82 23.76 17.07 23.76C17.57 23.76 17.76 23.26 17.76 22.81Z"/><path d="M39.95 15.76L39.95 4.24C39.95 4.11 39.85 4 39.71 4C39.58 4 39.47 4.11 39.47 4.24L39.47 15.76C39.47 15.89 39.58 16 39.71 16C39.85 16 39.95 15.89 39.95 15.76Z"/><path d="M48.13 9L48.13 8.69C47.9 8.71 47.61 8.72 47.38 8.72L46.51 8.69L46.51 9C46.88 9.01 46.99 9.24 46.99 9.43C46.99 9.52 46.97 9.56 46.93 9.67L45.91 12.22L44.79 9.43C44.73 9.3 44.73 9.26 44.73 9.26C44.73 9 45.12 9 45.3 9L45.3 8.69L44.21 8.72C43.94 8.72 43.54 8.71 43.24 8.69L43.24 9C43.87 9 43.91 9.06 44.04 9.37L45.48 12.92C45.54 13.06 45.56 13.11 45.69 13.11C45.82 13.11 45.86 13.02 45.9 12.92L47.21 9.67C47.3 9.44 47.47 9.01 48.13 9Z"/><path d="M51.79 14.64C51.79 14.57 51.74 14.55 51.7 14.55C51.64 14.55 51.63 14.6 51.61 14.65C51.37 15.37 50.74 15.37 50.67 15.37C50.32 15.37 50.04 15.16 49.88 14.9C49.67 14.57 49.67 14.11 49.67 13.85L51.62 13.85C51.77 13.85 51.79 13.85 51.79 13.71C51.79 13.01 51.42 12.33 50.54 12.33C49.73 12.33 49.08 13.06 49.08 13.93C49.08 14.87 49.82 15.55 50.62 15.55C51.48 15.55 51.79 14.77 51.79 14.64ZM51.33 13.71L49.67 13.71C49.71 12.66 50.3 12.49 50.54 12.49C51.26 12.49 51.33 13.43 51.33 13.71Z"/><path d="M55.74 15.47L55.74 15.25C55.38 15.25 55.2 15.25 55.2 15.04L55.2 13.71C55.2 13.1 55.2 12.89 54.98 12.64C54.88 12.52 54.65 12.38 54.24 12.38C53.73 12.38 53.4 12.68 53.21 13.11L53.21 12.38L52.22 12.45L52.22 12.67C52.71 12.67 52.77 12.72 52.77 13.06L52.77 14.94C52.77 15.25 52.69 15.25 52.22 15.25L52.22 15.47L53.01 15.45L53.8 15.47L53.8 15.25C53.33 15.25 53.25 15.25 53.25 14.94L53.25 13.65C53.25 12.92 53.75 12.53 54.19 12.53C54.64 12.53 54.71 12.91 54.71 13.31L54.71 14.94C54.71 15.25 54.64 15.25 54.17 15.25L54.17 15.47L54.96 15.45Z"/><path d="M59.28 12.64C59.28 12.52 59.2 12.3 58.93 12.3C58.79 12.3 58.48 12.34 58.18 12.63C57.89 12.4 57.6 12.38 57.44 12.38C56.79 12.38 56.31 12.86 56.31 13.4C56.31 13.71 56.46 13.97 56.64 14.12C56.55 14.22 56.42 14.46 56.42 14.7C56.42 14.92 56.51 15.18 56.73 15.32C56.31 15.44 56.08 15.74 56.08 16.02C56.08 16.53 56.78 16.91 57.63 16.91C58.46 16.91 59.19 16.56 59.19 16.01C59.19 15.76 59.09 15.41 58.73 15.21C58.36 15.02 57.95 15.02 57.53 15.02C57.35 15.02 57.05 15.02 57 15.01C56.78 14.98 56.63 14.76 56.63 14.54C56.63 14.51 56.63 14.35 56.75 14.21C57.02 14.41 57.31 14.43 57.44 14.43C58.09 14.43 58.58 13.94 58.58 13.41C58.58 13.15 58.46 12.89 58.29 12.73C58.54 12.49 58.79 12.45 58.92 12.45C58.92 12.45 58.97 12.45 58.99 12.46C58.91 12.49 58.88 12.57 58.88 12.65C58.88 12.77 58.97 12.85 59.08 12.85C59.15 12.85 59.28 12.8 59.28 12.64ZM58.05 13.4C58.05 13.59 58.04 13.81 57.94 13.99C57.88 14.07 57.72 14.27 57.44 14.27C56.83 14.27 56.83 13.57 56.83 13.41C56.83 13.22 56.84 12.99 56.95 12.82C57 12.73 57.16 12.54 57.44 12.54C58.05 12.54 58.05 13.24 58.05 13.4ZM58.82 16.02C58.82 16.4 58.32 16.75 57.64 16.75C56.93 16.75 56.45 16.39 56.45 16.02C56.45 15.7 56.71 15.44 57.02 15.42L57.44 15.42C58.04 15.42 58.82 15.42 58.82 16.02Z"/><path d="M61.12 15.47L61.12 15.25C60.66 15.25 60.63 15.22 60.63 14.95L60.63 12.38L59.65 12.45L59.65 12.67C60.1 12.67 60.17 12.71 60.17 13.06L60.17 14.94C60.17 15.25 60.09 15.25 59.62 15.25L59.62 15.47L60.39 15.45C60.63 15.45 60.88 15.46 61.12 15.47ZM60.73 11.24C60.73 11.05 60.57 10.87 60.36 10.87C60.12 10.87 59.98 11.07 59.98 11.24C59.98 11.43 60.14 11.61 60.35 11.61C60.59 11.61 60.73 11.42 60.73 11.24Z"/><path d="M65.08 15.47L65.08 15.25C64.72 15.25 64.54 15.25 64.53 15.04L64.53 13.71C64.53 13.1 64.53 12.89 64.32 12.64C64.22 12.52 63.99 12.38 63.58 12.38C63.07 12.38 62.74 12.68 62.55 13.11L62.55 12.38L61.56 12.45L61.56 12.67C62.05 12.67 62.1 12.72 62.1 13.06L62.1 14.94C62.1 15.25 62.03 15.25 61.56 15.25L61.56 15.47L62.35 15.45L63.13 15.47L63.13 15.25C62.66 15.25 62.59 15.25 62.59 14.94L62.59 13.65C62.59 12.92 63.08 12.53 63.53 12.53C63.97 12.53 64.05 12.91 64.05 13.31L64.05 14.94C64.05 15.25 63.97 15.25 63.5 15.25L63.5 15.47L64.3 15.45Z"/><path d="M68.13 14.64C68.13 14.57 68.08 14.55 68.04 14.55C67.98 14.55 67.96 14.6 67.95 14.65C67.7 15.37 67.07 15.37 67 15.37C66.65 15.37 66.37 15.16 66.21 14.9C66 14.57 66 14.11 66 13.85L67.96 13.85C68.11 13.85 68.13 13.85 68.13 13.71C68.13 13.01 67.75 12.33 66.88 12.33C66.07 12.33 65.42 13.06 65.42 13.93C65.42 14.87 66.16 15.55 66.96 15.55C67.82 15.55 68.13 14.77 68.13 14.64ZM67.67 13.71L66.01 13.71C66.05 12.66 66.64 12.49 66.88 12.49C67.6 12.49 67.67 13.43 67.67 13.71Z"/><path d="M71.65 15.38C71.65 15.35 71.63 15.32 71.61 15.3C70.57 14.52 69.88 12.52 69.88 10.92L69.88 10.08C69.88 8.48 70.57 6.48 71.61 5.7C71.63 5.68 71.65 5.65 71.65 5.62C71.65 5.57 71.6 5.52 71.55 5.52C71.53 5.52 71.51 5.53 71.49 5.54C70.39 6.37 69.34 8.37 69.34 10.08L69.34 10.92C69.34 12.63 70.39 14.63 71.49 15.46C71.51 15.47 71.53 15.48 71.55 15.48C71.6 15.48 71.65 15.43 71.65 15.38Z"/><path d="M75.54 11.76L75.54 11.19L75.29 11.19L75.29 11.74C75.29 12.48 74.99 12.86 74.62 12.86C73.95 12.86 73.95 11.95 73.95 11.78L73.95 9L75.38 9L75.38 8.69L73.95 8.69L73.95 6.85L73.7 6.85C73.69 7.67 73.39 8.74 72.41 8.78L72.41 9L73.26 9L73.26 11.76C73.26 12.99 74.19 13.11 74.55 13.11C75.26 13.11 75.54 12.4 75.54 11.76Z"/><path d="M78.99 10.92L78.99 10.08C78.99 8.37 77.94 6.37 76.84 5.54C76.82 5.53 76.8 5.52 76.78 5.52C76.73 5.52 76.68 5.57 76.68 5.62C76.68 5.65 76.7 5.68 76.72 5.7C77.76 6.48 78.45 8.48 78.45 10.08L78.45 10.92C78.45 12.52 77.76 14.52 76.72 15.3C76.7 15.32 76.68 15.35 76.68 15.38C76.68 15.43 76.73 15.48 76.78 15.48C76.8 15.48 76.82 15.47 76.84 15.46C77.94 14.63 78.99 12.63 78.99 10.92Z"/><path d="M84.99 11.13L84.99 10.55L82.34 10.55L82.34 11.13Z"/><path d="M92.86 9L92.86 8.69C92.63 8.71 92.34 8.72 92.11 8.72L91.24 8.69L91.24 9C91.61 9.01 91.72 9.24 91.72 9.43C91.72 9.52 91.7 9.56 91.66 9.67L90.64 12.22L89.52 9.43C89.46 9.3 89.46 9.26 89.46 9.26C89.46 9 89.85 9 90.03 9L90.03 8.69L88.94 8.72C88.67 8.72 88.27 8.71 87.97 8.69L87.97 9C88.6 9 88.64 9.06 88.77 9.37L90.21 12.92C90.27 13.06 90.29 13.11 90.42 13.11C90.55 13.11 90.59 13.02 90.63 12.92L91.94 9.67C92.03 9.44 92.2 9.01 92.86 9Z"/><path d="M97.11 14.17C97.11 13.47 96.65 12.89 96.06 12.75L95.17 12.54C94.73 12.43 94.46 12.05 94.46 11.65C94.46 11.16 94.84 10.73 95.38 10.73C96.55 10.73 96.71 11.88 96.75 12.19C96.75 12.24 96.75 12.28 96.83 12.28C96.92 12.28 96.92 12.24 96.92 12.11L96.92 10.7C96.92 10.58 96.92 10.54 96.85 10.54C96.8 10.54 96.79 10.54 96.74 10.63L96.5 11.03C96.29 10.82 96 10.54 95.38 10.54C94.6 10.54 94.01 11.15 94.01 11.89C94.01 12.47 94.38 12.99 94.93 13.17C95 13.2 95.36 13.29 95.85 13.41C96.04 13.45 96.25 13.5 96.45 13.76C96.59 13.94 96.66 14.18 96.66 14.41C96.66 14.9 96.31 15.41 95.73 15.41C95.52 15.41 94.99 15.37 94.62 15.03C94.21 14.65 94.19 14.2 94.19 13.95C94.18 13.88 94.12 13.88 94.1 13.88C94.01 13.88 94.01 13.93 94.01 14.06L94.01 15.46C94.01 15.58 94.01 15.62 94.09 15.62C94.14 15.62 94.14 15.61 94.19 15.53C94.19 15.53 94.21 15.51 94.44 15.13C94.66 15.37 95.11 15.62 95.73 15.62C96.55 15.62 97.11 14.94 97.11 14.17Z"/><path d="M102.43 12.67L102.43 12.45C102.28 12.47 102.07 12.47 101.92 12.47L101.27 12.45L101.27 12.67C101.52 12.68 101.68 12.8 101.68 13.01C101.68 13.05 101.68 13.06 101.64 13.15L101 14.95L100.31 12.99C100.28 12.91 100.28 12.89 100.28 12.86C100.28 12.67 100.55 12.67 100.69 12.67L100.69 12.45L99.96 12.47C99.75 12.47 99.55 12.47 99.34 12.45L99.34 12.67C99.6 12.67 99.71 12.68 99.78 12.78C99.81 12.82 99.89 13.03 99.94 13.16L99.34 14.85L98.67 12.99C98.64 12.9 98.64 12.89 98.64 12.86C98.64 12.67 98.91 12.67 99.05 12.67L99.05 12.45L98.29 12.47L97.64 12.45L97.64 12.67C97.99 12.67 98.07 12.69 98.15 12.92L99.04 15.39C99.07 15.49 99.09 15.55 99.18 15.55C99.27 15.55 99.29 15.51 99.32 15.41L100.03 13.43L100.74 15.41C100.77 15.49 100.79 15.55 100.88 15.55C100.98 15.55 101 15.48 101.02 15.41L101.84 13.12C101.97 12.77 102.19 12.68 102.43 12.67Z"/><path d="M104.29 15.47L104.29 15.25C103.83 15.25 103.8 15.22 103.8 14.95L103.8 12.38L102.82 12.45L102.82 12.67C103.28 12.67 103.34 12.71 103.34 13.06L103.34 14.94C103.34 15.25 103.26 15.25 102.8 15.25L102.8 15.47L103.57 15.45C103.81 15.45 104.06 15.46 104.29 15.47ZM103.91 11.24C103.91 11.05 103.75 10.87 103.54 10.87C103.3 10.87 103.16 11.07 103.16 11.24C103.16 11.43 103.32 11.61 103.53 11.61C103.77 11.61 103.91 11.42 103.91 11.24Z"/><path d="M107.01 11.03C107.01 10.77 106.75 10.54 106.38 10.54C105.89 10.54 105.29 10.91 105.29 11.65L105.29 12.45L104.74 12.45L104.74 12.67L105.29 12.67L105.29 14.94C105.29 15.25 105.22 15.25 104.75 15.25L104.75 15.47L105.55 15.45C105.83 15.45 106.16 15.45 106.44 15.47L106.44 15.25L106.29 15.25C105.77 15.25 105.76 15.18 105.76 14.92L105.76 12.67L106.55 12.67L106.55 12.45L105.74 12.45L105.74 11.64C105.74 11.03 106.07 10.69 106.38 10.69C106.4 10.69 106.51 10.69 106.61 10.74C106.53 10.77 106.4 10.86 106.4 11.03C106.4 11.19 106.51 11.33 106.7 11.33C106.9 11.33 107.01 11.19 107.01 11.03Z"/><path d="M108.98 14.6L108.98 14.2L108.8 14.2L108.8 14.59C108.8 15.11 108.59 15.37 108.33 15.37C107.86 15.37 107.86 14.74 107.86 14.62L107.86 12.67L108.86 12.67L108.86 12.45L107.86 12.45L107.86 11.17L107.69 11.17C107.68 11.74 107.47 12.49 106.79 12.52L106.79 12.67L107.38 12.67L107.38 14.6C107.38 15.46 108.03 15.55 108.28 15.55C108.78 15.55 108.98 15.05 108.98 14.6Z"/><path d="M114.39 10.91L114.39 10.69L113.56 10.71L112.73 10.69L112.73 10.91C113.45 10.91 113.45 11.24 113.45 11.42L113.45 13.85C113.45 14.85 112.77 15.41 112.11 15.41C111.78 15.41 110.95 15.23 110.95 13.9L110.95 11.24C110.95 10.98 110.96 10.91 111.5 10.91L111.67 10.91L111.67 10.69C111.43 10.71 110.91 10.71 110.64 10.71C110.38 10.71 109.85 10.71 109.61 10.69L109.61 10.91L109.77 10.91C110.31 10.91 110.33 10.98 110.33 11.24L110.33 13.87C110.33 14.86 111.14 15.62 112.09 15.62C112.9 15.62 113.53 14.97 113.65 14.18C113.67 14.04 113.67 13.97 113.67 13.69L113.67 11.45C113.67 11.22 113.67 10.91 114.39 10.91Z"/><path d="M116.96 15.47L116.96 15.25L116.77 15.25C116.22 15.25 116.2 15.18 116.2 14.92L116.2 11.24C116.2 10.98 116.22 10.91 116.77 10.91L116.96 10.91L116.96 10.69C116.71 10.71 116.16 10.71 115.89 10.71C115.62 10.71 115.07 10.71 114.82 10.69L114.82 10.91L115 10.91C115.56 10.91 115.58 10.98 115.58 11.24L115.58 14.92C115.58 15.18 115.56 15.25 115 15.25L114.82 15.25L114.82 15.47C115.07 15.45 115.62 15.45 115.89 15.45C116.16 15.45 116.71 15.45 116.96 15.47Z"/><path d="M120.47 15.38C120.47 15.35 120.45 15.32 120.43 15.3C119.39 14.52 118.7 12.52 118.7 10.92L118.7 10.08C118.7 8.48 119.39 6.48 120.43 5.7C120.45 5.68 120.47 5.65 120.47 5.62C120.47 5.57 120.42 5.52 120.37 5.52C120.35 5.52 120.33 5.53 120.31 5.54C119.21 6.37 118.16 8.37 118.16 10.08L118.16 10.92C118.16 12.63 119.21 14.63 120.31 15.46C120.33 15.47 120.35 15.48 120.37 15.48C120.42 15.48 120.47 15.43 120.47 15.38Z"/><path d="M124.36 11.76L124.36 11.19L124.11 11.19L124.11 11.74C124.11 12.48 123.81 12.86 123.44 12.86C122.77 12.86 122.77 11.95 122.77 11.78L122.77 9L124.2 9L124.2 8.69L122.77 8.69L122.77 6.85L122.52 6.85C122.51 7.67 122.21 8.74 121.23 8.78L121.23 9L122.08 9L122.08 11.76C122.08 12.99 123.01 13.11 123.37 13.11C124.08 13.11 124.36 12.4 124.36 11.76Z"/><path d="M127.81 10.92L127.81 10.08C127.81 8.37 126.76 6.37 125.66 5.54C125.64 5.53 125.62 5.52 125.6 5.52C125.55 5.52 125.5 5.57 125.5 5.62C125.5 5.65 125.52 5.68 125.54 5.7C126.58 6.48 127.27 8.48 127.27 10.08L127.27 10.92C127.27 12.52 126.58 14.52 125.54 15.3C125.52 15.32 125.5 15.35 125.5 15.38C125.5 15.43 125.55 15.48 125.6 15.48C125.62 15.48 125.64 15.47 125.66 15.46C126.76 14.63 127.81 12.63 127.81 10.92Z"/><path d="M132.4 15.76L132.4 4.24C132.4 4.11 132.29 4 132.16 4C132.03 4 131.92 4.11 131.92 4.24L131.92 15.76C131.92 15.89 132.03 16 132.16 16C132.29 16 132.4 15.89 132.4 15.76Z"/><path d="M146.29 12.25L140.81 9.66L146.29 7.07C146.53 6.96 146.36 6.6 146.11 6.71L140.3 9.46C140.13 9.54 140.13 9.78 140.3 9.86L146.11 12.61C146.36 12.72 146.53 12.36 146.29 12.25ZM146.4 13.99C146.4 13.88 146.31 13.79 146.2 13.79L140.34 13.79C140.23 13.79 140.14 13.88 140.14 13.99C140.14 14.1 140.23 14.19 140.34 14.19L146.2 14.19C146.31 14.19 146.4 14.1 146.4 13.99Z"/><path d="M156.91 13L156.91 12.69L156.59 12.69C155.69 12.69 155.66 12.58 155.66 12.21L155.66 6.6C155.66 6.36 155.66 6.34 155.43 6.34C154.81 6.98 153.93 6.98 153.61 6.98L153.61 7.29C153.81 7.29 154.4 7.29 154.92 7.03L154.92 12.21C154.92 12.57 154.89 12.69 153.99 12.69L153.67 12.69L153.67 13C154.02 12.97 154.89 12.97 155.29 12.97C155.69 12.97 156.56 12.97 156.91 13Z"/><path d="M162.32 9.8C162.32 9 162.27 8.2 161.92 7.46C161.46 6.5 160.64 6.34 160.22 6.34C159.62 6.34 158.89 6.6 158.48 7.53C158.16 8.22 158.11 9 158.11 9.8C158.11 10.55 158.15 11.45 158.56 12.21C158.99 13.02 159.72 13.22 160.21 13.22C160.75 13.22 161.51 13.01 161.95 12.06C162.27 11.37 162.32 10.59 162.32 9.8ZM161.49 9.68C161.49 10.43 161.49 11.11 161.38 11.75C161.23 12.7 160.66 13 160.21 13C159.82 13 159.23 12.75 159.05 11.79C158.94 11.19 158.94 10.27 158.94 9.68C158.94 9.04 158.94 8.38 159.02 7.84C159.21 6.65 159.96 6.56 160.21 6.56C160.54 6.56 161.2 6.74 161.39 7.73C161.49 8.29 161.49 9.05 161.49 9.68Z"/><path d="M165.21 8.06L165.21 7.66L163.35 7.66L163.35 8.06Z"/><path d="M168.81 7.94C168.81 7.05 168.18 6.38 167.41 6.38C166.93 6.38 166.67 6.74 166.53 7.07L166.53 6.91C166.53 5.14 167.4 4.88 167.76 4.88C167.92 4.88 168.22 4.93 168.37 5.16C168.27 5.16 167.99 5.16 167.99 5.48C167.99 5.7 168.16 5.8 168.31 5.8C168.42 5.8 168.63 5.74 168.63 5.46C168.63 5.04 168.32 4.71 167.74 4.71C166.85 4.71 165.9 5.61 165.9 7.16C165.9 9.03 166.71 9.52 167.36 9.52C168.14 9.52 168.81 8.87 168.81 7.94ZM168.18 7.94C168.18 8.27 168.18 8.62 168.06 8.87C167.85 9.29 167.53 9.33 167.36 9.33C166.92 9.33 166.71 8.91 166.67 8.8C166.55 8.47 166.55 7.91 166.55 7.79C166.55 7.24 166.77 6.54 167.4 6.54C167.51 6.54 167.83 6.54 168.05 6.98C168.18 7.24 168.18 7.59 168.18 7.94Z"/></svg><math class="td-math-a11y" xmlns="http://www.w3.org/1998/Math/MathML"><mrow><msub><mrow><mo>max</mo></mrow><mrow><mi>t</mi></mrow></msub><mspace width="0.28em"/><mtext> </mtext><mo>|</mo><mspace width="0.17em"/><mtext> </mtext><msub><mrow><mi>v</mi></mrow><mrow><mi>engine</mi></mrow></msub><mtext>(</mtext><mi>t</mi><mtext>)</mtext><mtext> </mtext><mtext>-</mtext><mtext> </mtext><msub><mrow><mi>v</mi></mrow><mrow><mi>SwiftUI</mi></mrow></msub><mtext>(</mtext><mi>t</mi><mtext>)</mtext><mtext> </mtext><mspace width="0.17em"/><mo>|</mo><mtext> </mtext><mspace width="0.28em"/><mo>≤</mo><mspace width="0.28em"/><mtext> </mtext><mn>1</mn><msup><mrow><mn>0</mn></mrow><mrow><mrow><mtext>-</mtext><mn>6</mn></mrow></mrow></msup></mrow></math></div>
<p>Sampled point by point, the two springs are the same number to six decimals.</p>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">The engine&#39;s spring rides on SwiftUI&#39;s</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="The engine&#39;s spring rides on SwiftUI&#39;s"
>
<desc>line chart with 0 labels and 1 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="186.17"
  x2="696"
  y2="186.17"
></line>
<text
  class="td-chart-value"
  x="70"
  y="190.17"
  text-anchor="end"
>0.5</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="70.33"
  x2="696"
  y2="70.33"
></line>
<text
  class="td-chart-value"
  x="70"
  y="74.33"
  text-anchor="end"
>1</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<text
  class="td-chart-label"
  x="80"
  y="324"
  text-anchor="middle"
>0</text>
<text
  class="td-chart-label"
  x="388"
  y="324"
  text-anchor="middle"
>4</text>
<text
  class="td-chart-label"
  x="696"
  y="324"
  text-anchor="middle"
>8</text>
<polyline class="td-chart-line td-chart-series-0" points="80,302 157,116.67 234,24 311,81.92 388,58.75 465,72.65 542,68.02 619,70.33 696,70.33"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="80"
  cy="302"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="157"
  cy="116.67"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="234"
  cy="24"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="311"
  cy="81.92"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="388"
  cy="58.75"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="465"
  cy="72.65"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="542"
  cy="68.02"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="619"
  cy="70.33"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="696"
  cy="70.33"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>Time</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>Progress</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>Progress</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Progress: (0, 0)</title>
<circle class="td-chart-hit" cx="80" cy="302" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="5.4" y="260" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="14.4" y="280">Progress: (0, 0)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Progress: (1, 0.8)</title>
<circle class="td-chart-hit" cx="157" cy="116.67" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="74.2" y="74.67" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="83.2" y="94.67">Progress: (1, 0.8)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Progress: (2, 1.2)</title>
<circle class="td-chart-hit" cx="234" cy="24" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="151.2" y="36" width="165.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="160.2" y="56">Progress: (2, 1.2)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Progress: (3, 0.95)</title>
<circle class="td-chart-hit" cx="311" cy="81.92" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="224.1" y="39.92" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="233.1" y="59.92">Progress: (3, 0.95)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Progress: (4, 1.05)</title>
<circle class="td-chart-hit" cx="388" cy="58.75" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="301.1" y="16.75" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="310.1" y="36.75">Progress: (4, 1.05)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Progress: (5, 0.99)</title>
<circle class="td-chart-hit" cx="465" cy="72.65" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="378.1" y="30.65" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="387.1" y="50.65">Progress: (5, 0.99)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Progress: (6, 1.01)</title>
<circle class="td-chart-hit" cx="542" cy="68.02" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="455.1" y="26.02" width="173.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="464.1" y="46.02">Progress: (6, 1.01)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Progress: (7, 1)</title>
<circle class="td-chart-hit" cx="619" cy="70.33" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="544.4" y="28.33" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="553.4" y="48.33">Progress: (7, 1)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Progress: (8, 1)</title>
<circle class="td-chart-hit" cx="696" cy="70.33" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="566.8" y="28.33" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="575.8" y="48.33">Progress: (8, 1)</text>
</g>
</g>
</svg>
</div>
</figure>
<h2>Measuring pixels: compare the rendered bytes</h2>
<p>Frames prove position. Pixels prove the rest: the actual color drawn, and the paint order
of overlapping fills. SwiftUI’s own <code>ImageRenderer</code> rasterizes the view; the engine’s
display list is rasterized by a reference renderer; we diff the buffers channel by channel.</p>
<p><img src="https://aleahim.com/images/blog/the-swiftui-oracle/9-pixel-diff.jpg" alt="Two pictures, compared dot by dot"></p>
<pre><code class="language-swift"><span class="tok-comment">/// Render a SwiftUI view to an RGBA8 buffer in the same space/scale/orientation.</span>
<span class="tok-keyword">private</span> <span class="tok-keyword">func</span> <span class="tok-function">snapshot</span>(_ view<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">View</span>, size<span class="tok-operator">:</span> <span class="tok-type">CGSize</span>, scale<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>) <span class="tok-keyword">throws</span> <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> [<span class="tok-type">UInt8</span>] {
    <span class="tok-keyword">let</span> renderer <span class="tok-operator">=</span> <span class="tok-type">ImageRenderer</span>(content<span class="tok-operator">:</span> view<span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> size<span class="tok-operator">.</span>width, height<span class="tok-operator">:</span> size<span class="tok-operator">.</span>height))
    renderer<span class="tok-operator">.</span>scale <span class="tok-operator">=</span> scale
    renderer<span class="tok-operator">.</span>color<span class="tok-type">Mode</span> <span class="tok-operator">=</span> <span class="tok-operator">.</span>non<span class="tok-type">Linear</span>
    <span class="tok-keyword">let</span> image <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-attribute">#require</span>(renderer<span class="tok-operator">.</span>cg<span class="tok-type">Image</span>, <span class="tok-string">"ImageRenderer produced no image"</span>)
    <span class="tok-keyword">let</span> w <span class="tok-operator">=</span> <span class="tok-type">Int</span>(size<span class="tok-operator">.</span>width <span class="tok-operator">*</span> scale), h <span class="tok-operator">=</span> <span class="tok-type">Int</span>(size<span class="tok-operator">.</span>height <span class="tok-operator">*</span> scale)
    <span class="tok-keyword">let</span> (ctx, raw) <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-function">context</span>(width<span class="tok-operator">:</span> w, height<span class="tok-operator">:</span> h, scale<span class="tok-operator">:</span> <span class="tok-number">1</span>, flip<span class="tok-type">ForDrawing</span><span class="tok-operator">:</span> <span class="tok-literal">true</span>)
    <span class="tok-keyword">defer</span> { raw<span class="tok-operator">.</span><span class="tok-function">deallocate</span>() }
    ctx<span class="tok-operator">.</span><span class="tok-function">draw</span>(image, <span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-type">CGRect</span>(x<span class="tok-operator">:</span> <span class="tok-number">0</span>, y<span class="tok-operator">:</span> <span class="tok-number">0</span>, width<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>(w), height<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>(h)))
    <span class="tok-keyword">return</span> <span class="tok-function">bytes</span>(raw, count<span class="tok-operator">:</span> w <span class="tok-operator">*</span> <span class="tok-number">4</span> <span class="tok-operator">*</span> h)
}

<span class="tok-keyword">private</span> <span class="tok-keyword">func</span> <span class="tok-function">assertPixelsMatch</span>(
    _ name<span class="tok-operator">:</span> <span class="tok-type">String</span>,
    list<span class="tok-operator">:</span> <span class="tok-type">DisplayList</span>,
    view<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">SwiftUI</span><span class="tok-operator">.</span><span class="tok-type">View</span>,
    size<span class="tok-operator">:</span> <span class="tok-type">CGSize</span>,
    scale<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span> <span class="tok-operator">=</span> <span class="tok-number">2</span>,
    tolerance<span class="tok-operator">:</span> <span class="tok-type">Int</span> <span class="tok-operator">=</span> <span class="tok-number">2</span>
) <span class="tok-keyword">throws</span> {
    <span class="tok-keyword">let</span> engine <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-function">rasterize</span>(list, size<span class="tok-operator">:</span> size, scale<span class="tok-operator">:</span> scale)
    <span class="tok-keyword">let</span> swiftui <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-function">snapshot</span>(view, size<span class="tok-operator">:</span> size, scale<span class="tok-operator">:</span> scale)
    <span class="tok-attribute">#expect</span>(<span class="tok-operator">!</span>engine<span class="tok-operator">.</span>is<span class="tok-type">Empty</span> <span class="tok-operator">&amp;</span><span class="tok-operator">&amp;</span> engine<span class="tok-operator">.</span>count <span class="tok-operator">=</span><span class="tok-operator">=</span> swiftui<span class="tok-operator">.</span>count, <span class="tok-string">"\(name): buffer size mismatch"</span>)
    <span class="tok-keyword">var</span> max<span class="tok-type">Diff</span> <span class="tok-operator">=</span> <span class="tok-number">0</span>, exceeding <span class="tok-operator">=</span> <span class="tok-number">0</span>
    <span class="tok-keyword">for</span> i <span class="tok-keyword">in</span> <span class="tok-number">0</span> <span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">&lt;</span> <span class="tok-function">min</span>(engine<span class="tok-operator">.</span>count, swiftui<span class="tok-operator">.</span>count) {
        <span class="tok-keyword">let</span> diff <span class="tok-operator">=</span> <span class="tok-function">abs</span>(<span class="tok-type">Int</span>(engine[i]) <span class="tok-operator">-</span> <span class="tok-type">Int</span>(swiftui[i]))
        max<span class="tok-type">Diff</span> <span class="tok-operator">=</span> <span class="tok-function">max</span>(max<span class="tok-type">Diff</span>, diff)
        <span class="tok-keyword">if</span> diff <span class="tok-operator">&gt;</span> tolerance { exceeding <span class="tok-operator">+</span><span class="tok-operator">=</span> <span class="tok-number">1</span> }
    }
    <span class="tok-attribute">#expect</span>(exceeding <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-number">0</span>, <span class="tok-string">"\(name): \(exceeding) channels exceed tol \(tolerance) (maxDiff \(maxDiff))"</span>)
}</code></pre>
<p>The tolerance here is 2 on an 8-bit channel: the quantization floor is one least-significant
bit, and integer-aligned fills at scale 2 have crisp edges, so there is no anti-aliasing
slack to hide behind.</p>
<h2>What it all adds up to</h2>
<p>There are 125 of these tests today, across 19 files. The same do-it-twice method holds
every layer the engine rebuilds.</p>
<figure class="td-chart td-chart-bar">
<figcaption class="td-chart-caption">125 oracle tests holding the engine to SwiftUI</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 360"
  role="img"
  aria-label="125 oracle tests holding the engine to SwiftUI"
>
<desc>bar chart with 6 labels and 1 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="209.33"
  x2="696"
  y2="209.33"
></line>
<text
  class="td-chart-value"
  x="70"
  y="213.33"
  text-anchor="end"
>20</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="116.67"
  x2="696"
  y2="116.67"
></line>
<text
  class="td-chart-value"
  x="70"
  y="120.67"
  text-anchor="end"
>40</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>60</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<rect
  class="td-chart-bar td-chart-series-0"
  x="114.33"
  y="278.83"
  width="32"
  height="23.17"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="217"
  y="125.93"
  width="32"
  height="176.07"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="319.67"
  y="283.47"
  width="32"
  height="18.53"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="422.33"
  y="65.7"
  width="32"
  height="236.3"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="525"
  y="288.1"
  width="32"
  height="13.9"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="627.67"
  y="190.8"
  width="32"
  height="111.2"
  rx="4"
></rect>
<text
  class="td-chart-label"
  x="131.33"
  y="324"
  text-anchor="middle"
>Graph</text>
<text
  class="td-chart-label"
  x="234"
  y="324"
  text-anchor="middle"
>Animation</text>
<text
  class="td-chart-label"
  x="336.67"
  y="324"
  text-anchor="middle"
>Identity</text>
<text
  class="td-chart-label"
  x="439.33"
  y="324"
  text-anchor="middle"
>Layout</text>
<text
  class="td-chart-label"
  x="542"
  y="324"
  text-anchor="middle"
>DisplayList</text>
<text
  class="td-chart-label"
  x="644.67"
  y="324"
  text-anchor="middle"
>Pixel</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>Tests</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>Tests</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Graph: 5</title>
<rect class="td-chart-hit" x="114.33" y="274.42" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="88.53" y="240.83" width="83.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="97.53" y="260.83">Graph: 5</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Animation: 38</title>
<rect class="td-chart-hit" x="217" y="125.93" width="32" height="176.07"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="170.7" y="87.93" width="124.6" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="179.7" y="107.93">Animation: 38</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Identity: 4</title>
<rect class="td-chart-hit" x="319.67" y="276.73" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="281.57" y="245.47" width="108.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="290.57" y="265.47">Identity: 4</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Layout: 51</title>
<rect class="td-chart-hit" x="422.33" y="65.7" width="32" height="236.3"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="388.33" y="27.7" width="100" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="397.33" y="47.7">Layout: 51</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>DisplayList: 3</title>
<rect class="td-chart-hit" x="525" y="279.05" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="474.6" y="250.1" width="132.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="483.6" y="270.1">DisplayList: 3</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Pixel: 24</title>
<rect class="td-chart-hit" x="627.67" y="190.8" width="32" height="111.2"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="597.77" y="152.8" width="91.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="606.77" y="172.8">Pixel: 24</text>
</g>
</g>
</svg>
</div>
</figure>
<h2>What measuring caught that reading never would</h2>
<p>The payoff: the measurement caught a bug in the engine that reading the code could not. The
spring decided it had come to rest using the bare decay envelope, which undercounts the long
tail of a critically damped or overdamped spring. The code looked correct. Measured against
SwiftUI, the spring clamped a few percent short of its target, a visible snap. The oracle
failed with the exact residual, and the settling time was rederived from the real basis of
the oscillator. Reading gives you the happy path. Measuring gives you the edges, where the
interesting bugs live.</p>
<h2>One honest caveat about the animation path</h2>
<p>A committed animation keeps running smoothly when the main thread is busy only for one of
two paths. Layer-level properties, opacity and transform, lower to Core Animation and are
interpolated on the render server’s own clock, off the main thread. Value-driven animations,
a spring on a custom value, are re-pulled through the graph every frame on the main thread,
and those do stutter if you block it. The oracle measures the value and velocity of the
motion; which thread interpolates it is a property of the lowering path. Worth stating
precisely, since the rest of this post is about precision.</p>
<h2>Colophon: every figure was made by my own software</h2>
<p>No third-party drawing or charting tool was used anywhere in this post.</p>
<ul><li><p>The conceptual diagrams (the wall, the two pieces, the counters, the negotiation, the
pixel comparison) were drawn by <strong>PureDraw</strong>, my dependency-free Swift-native 2D vector
engine, through its <code>GraphicsContext</code> API. PureDraw rasterized them to the JPEGs shown here with its own <code>BitmapRenderer</code> and <code>JPEGEncoder</code>, and also produced scalable SVG and PDF masters. No external image tool touched them.</p></li><li><p>The bar chart, the spring plot, and every mathematical formula were rendered by
<strong>TileDown</strong>, my static-site engine, from plain-text fences in this Markdown file.</p></li><li><p>This page was assembled by <strong>TileDown</strong>, and its PDF was typeset by <strong>MarkdownPDF</strong>, my Markdown-to-PDF engine.</p></li></ul>
<p><strong>PureDraw</strong> is part of <strong><a href="https://slayermotion.com">SlayerMotion</a></strong>, the graphics engine family this series is about. <strong>TileDown</strong> and <strong>MarkdownPDF</strong> are separate projects of mine, not part of SlayerMotion. All three are my own software; none of it is anyone else’s.</p>]]></content:encoded>
</item>
<item>
<title>SwiftUI Is One Graph, Over 40+ Years of Engineering</title>
<link>https://aleahim.com/blog/swiftui-is-one-graph/</link>
<guid isPermaLink="true">https://aleahim.com/blog/swiftui-is-one-graph/</guid>
<pubDate>Thu, 25 Jun 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>SwiftUI is the thin graph sitting above 40+ years of engineering. Measured against the real framework and read against Apple&apos;s own patent, it is a single demand-driven graph, and the least remarkable engine in the stack it rests on. Here is SwiftUI laid bare, with a hint of the far more interesting machines underneath.</description>
<content:encoded><![CDATA[<h1>SwiftUI Is One Graph, Over 40+ Years of Engineering</h1>
<p>I wanted to know what SwiftUI really is, not what the tutorials say it is. So I came at it from two directions that cannot collude. I measured the real framework’s behavior until it was predictable, the way you probe any black box, and I read Apple’s own patent on it, line by line. The shipping framework is the oracle. The granted patent is Apple describing its own machine. When the two agree, you are no longer guessing.</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart LR
  B[&quot;Real framework behavior&quot;] --&gt; M[&quot;One demand-driven graph&quot;]
  P[&quot;Apple&#39;s granted patent&quot;] --&gt; M
</pre>
</figure>
<p>And they agree, almost field for field. What they describe together is simpler and stranger than the usual story: not a view tree that gets diffed, but a single demand-driven graph. I will show you that graph, because it is genuinely elegant. Then, at the end, I will tell you why it is the part of Apple’s stack I find least interesting, and what I have been doing about that. First the engine.</p>
<h2>A view is a value, not an object</h2>
<p>When you write a SwiftUI view you are not creating a thing on screen. You are describing what the screen should look like, as a cheap struct that gets thrown away and rebuilt constantly. This trips people up because it feels wasteful. It is not. The struct is disposable on purpose. The part of your UI that actually persists lives somewhere else entirely.</p>
<p>That somewhere else is the attribute graph, and it is the whole game.</p>
<h2>The attribute graph</h2>
<p>Every view compiles into a graph of attributes. An attribute is one node with exactly two things: a cached value, and a rule that computes that value from its inputs. A view’s <code>body</code> is itself an attribute whose rule is “evaluate this body.”</p>
<p>The clever part is how edges form. When a rule runs and reads another attribute, an edge is recorded between them. Dependencies are never declared. They are discovered, by watching what each body actually reads while it runs. You get the dependency graph for free, just by evaluating.</p>
<p>Now the reactive behavior everyone loves, explained without magic. You change one piece of state. SwiftUI does not rebuild the world. It marks that single source attribute dirty and pushes the dirty flag forward along the edges, to exactly the attributes that depended on it and to nobody else. That set is the cone. Then, lazily, when the screen needs a value, it pulls. It walks down to the dirty inputs, recomputes only those, caches them, and bubbles the result back up. An attribute whose inputs did not change returns its cache and its rule never runs. That is why a screen with a thousand views re-runs the body of only the one that changed.</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart TD
  S[&quot;@State count, a source&quot;] --&gt;|dirty| L[&quot;Label.body&quot;]
  L --&gt; T[&quot;Text attribute&quot;]
  S -.-&gt;|no edge, untouched| O[&quot;Other.body&quot;]
</pre>
</figure>
<p>The cone is the whole efficiency story. A naive rebuild touches every body in the interface, so its cost grows with the screen. The graph touches only the dirty node and what truly depends on it, so its cost tracks the change, not the size of the UI.</p>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">Bodies re-run for one change as the screen grows</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="Bodies re-run for one change as the screen grows"
>
<desc>line chart with 0 labels and 2 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="246.4"
  x2="696"
  y2="246.4"
></line>
<text
  class="td-chart-value"
  x="70"
  y="250.4"
  text-anchor="end"
>200</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="190.8"
  x2="696"
  y2="190.8"
></line>
<text
  class="td-chart-value"
  x="70"
  y="194.8"
  text-anchor="end"
>400</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="135.2"
  x2="696"
  y2="135.2"
></line>
<text
  class="td-chart-value"
  x="70"
  y="139.2"
  text-anchor="end"
>600</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="79.6"
  x2="696"
  y2="79.6"
></line>
<text
  class="td-chart-value"
  x="70"
  y="83.6"
  text-anchor="end"
>800</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>1000</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<text
  class="td-chart-label"
  x="80"
  y="324"
  text-anchor="middle"
>200</text>
<text
  class="td-chart-label"
  x="388"
  y="324"
  text-anchor="middle"
>600</text>
<text
  class="td-chart-label"
  x="696"
  y="324"
  text-anchor="middle"
>1000</text>
<polyline class="td-chart-line td-chart-series-0" points="80,246.4 234,190.8 388,135.2 542,79.6 696,24"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="80"
  cy="246.4"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="234"
  cy="190.8"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="388"
  cy="135.2"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="542"
  cy="79.6"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="696"
  cy="24"
  r="4"
></circle>
<polyline class="td-chart-line td-chart-series-1" points="80,301.72 234,301.72 388,301.72 542,301.72 696,301.72"></polyline>
<circle
  class="td-chart-point td-chart-series-1"
  cx="80"
  cy="301.72"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="234"
  cy="301.72"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="388"
  cy="301.72"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="542"
  cy="301.72"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-1"
  cx="696"
  cy="301.72"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>Views on screen</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>Bodies re-run</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>Rebuild the world</text>
<rect
  class="td-chart-series-1"
  x="247.84"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="265.84"
  y="346"
  text-anchor="start"
>Demand-driven graph</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Rebuild the world: (200, 200)</title>
<circle class="td-chart-hit" cx="80" cy="246.4" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="4" y="204.4" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="13" y="224.4">Rebuild the world: (200, 200)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Rebuild the world: (400, 400)</title>
<circle class="td-chart-hit" cx="234" cy="190.8" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="106.1" y="148.8" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="115.1" y="168.8">Rebuild the world: (400, 400)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Rebuild the world: (600, 600)</title>
<circle class="td-chart-hit" cx="388" cy="135.2" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="260.1" y="93.2" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="269.1" y="113.2">Rebuild the world: (600, 600)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Rebuild the world: (800, 800)</title>
<circle class="td-chart-hit" cx="542" cy="79.6" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="414.1" y="37.6" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="423.1" y="57.6">Rebuild the world: (800, 800)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Rebuild the world: (1000, 1000)</title>
<circle class="td-chart-hit" cx="696" cy="24" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="443.8" y="36" width="272.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="452.8" y="56">Rebuild the world: (1000, 1000)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>Demand-driven graph: (200, 1)</title>
<circle class="td-chart-hit" cx="80" cy="301.72" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="4" y="259.72" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="13" y="279.72">Demand-driven graph: (200, 1)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>Demand-driven graph: (400, 1)</title>
<circle class="td-chart-hit" cx="234" cy="301.72" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="106.1" y="259.72" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="115.1" y="279.72">Demand-driven graph: (400, 1)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>Demand-driven graph: (600, 1)</title>
<circle class="td-chart-hit" cx="388" cy="301.72" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="260.1" y="259.72" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="269.1" y="279.72">Demand-driven graph: (600, 1)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>Demand-driven graph: (800, 1)</title>
<circle class="td-chart-hit" cx="542" cy="301.72" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="414.1" y="259.72" width="255.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="423.1" y="279.72">Demand-driven graph: (800, 1)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-1" tabindex="0"><title>Demand-driven graph: (1000, 1)</title>
<circle class="td-chart-hit" cx="696" cy="301.72" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="452" y="259.72" width="264" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="461" y="279.72">Demand-driven graph: (1000, 1)</text>
</g>
</g>
</svg>
</div>
</figure>
<p>There is one more piece that matters for performance. If a recomputed value comes out equal to what it was before, propagation stops there. An unchanged value never disturbs anything downstream, so a state change that happens to produce the same result costs almost nothing.</p>
<h2>State and identity</h2>
<p>Because the view struct is disposable, your <code>@State</code> cannot live inside it. It lives in persistent storage, keyed by the view’s identity. Identity is structural, meaning the view’s type and position in the tree. An explicit <code>id</code> does not override that, it pairs with it: change the identifier and the view gets a new identity at that spot, but reuse the same identifier elsewhere and the two stay distinct.</p>
<p>This one rule explains a lot of confusing behavior. As long as the identity is stable, your state survives every rebuild of the struct. The moment the identity changes, by changing <code>.id</code> or by removing and reinserting the view, the old state is destroyed and a fresh one is created at its default. It is also why a <code>List</code> can recycle its rows without losing their state. The state follows the identity, not the position on screen. Reorder the data and each row’s state travels with its identifier.</p>
<h2>Layout is a negotiation</h2>
<p>Layout is three steps and one rule. The parent proposes a size to the child. The child chooses its own size. The parent then places the child. The rule is that the parent never forces a size on the child. A stack divides its space among its children, giving the least flexible ones their size first and sharing what is left. Text measures itself through the text engine, with kerning and the font’s own line metrics, which is why a label is exactly as wide as it needs to be.</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart TD
  P1[&quot;Parent proposes a size&quot;] --&gt; C1[&quot;Child chooses its own size&quot;]
  C1 --&gt; P2[&quot;Parent places the child&quot;]
</pre>
</figure>
<h2>How it becomes pixels, and the part people get wrong</h2>
<p>SwiftUI sits on Core Animation. Core Animation holds the layer state, position, opacity, transform, the properties the GPU composites and the render server interpolates. Core Graphics paints the content, text and shapes, into bitmaps that become a layer’s contents.</p>
<p>Here is the part most people get wrong. <strong>SwiftUI does not make one layer per view. UIKit does that, where every view is layer backed one to one. SwiftUI coalesces. A stack of ten text labels is usually a single layer with a single drawing, not eleven layers.</strong> A view earns its own layer only when it needs a layer level property, like opacity or a transform. This is a real reason SwiftUI is efficient. A long list is a handful of layers for the compositor to manage, not thousands. The tradeoff is that coalesced content has to be redrawn when it changes, while a dedicated layer can move without a redraw. For typical interfaces that trade is a clear win.</p>
<figure class="td-chart td-chart-bar">
<figcaption class="td-chart-caption">Layers for a stack of ten text labels</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 360"
  role="img"
  aria-label="Layers for a stack of ten text labels"
>
<desc>bar chart with 2 labels and 1 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="186.17"
  x2="696"
  y2="186.17"
></line>
<text
  class="td-chart-value"
  x="70"
  y="190.17"
  text-anchor="end"
>5</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="70.33"
  x2="696"
  y2="70.33"
></line>
<text
  class="td-chart-value"
  x="70"
  y="74.33"
  text-anchor="end"
>10</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<rect
  class="td-chart-bar td-chart-series-0"
  x="217"
  y="47.17"
  width="32"
  height="254.83"
  rx="4"
></rect>
<rect
  class="td-chart-bar td-chart-series-0"
  x="525"
  y="278.83"
  width="32"
  height="23.17"
  rx="4"
></rect>
<text
  class="td-chart-label"
  x="234"
  y="324"
  text-anchor="middle"
>One layer per view</text>
<text
  class="td-chart-label"
  x="542"
  y="324"
  text-anchor="middle"
>SwiftUI coalesced</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>Layers created</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>Layers</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>One layer per view: 11</title>
<rect class="td-chart-hit" x="217" y="47.17" width="32" height="254.83"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="133.8" y="9.17" width="198.4" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="142.8" y="29.17">One layer per view: 11</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>SwiftUI coalesced: 1</title>
<rect class="td-chart-hit" x="525" y="274.42" width="32" height="32"></rect>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="450" y="240.83" width="182" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="459" y="260.83">SwiftUI coalesced: 1</text>
</g>
</g>
</svg>
</div>
</figure>
<h2>Animation, the beautiful part</h2>
<p>When you change a value inside <code>withAnimation</code>, the model value jumps straight to its target. It does not crawl there. Instead the framework makes a copy of that destination, and into the copy it injects an intermediate value, interpolated for this exact instant. The view draws the copy. Your data is already at the final value. Only the presentation is in flight.</p>
<p>Each animation is a tiny record: a from value, a to value, a timing function, and a start time. That is all it needs.</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart TD
  R[&quot;Animation record&quot;] --&gt; A[&quot;from value&quot;]
  R --&gt; B[&quot;to value&quot;]
  R --&gt; C[&quot;animation function&quot;]
  R --&gt; D[&quot;start time&quot;]
</pre>
</figure>
<p>Time itself is just another input to the graph. Every frame a clock ticks, that tick dirties only the animated attributes, and they re-pull a fresh interpolated value through the same cone machinery as everything else. The interpolation works on a delta vector, the difference between from and to, scaled by the curve.</p>
<p>A spring is not a special case. It is a damped harmonic oscillator solved over time, which is exactly why it overshoots and then settles. And because the animation is committed once and the render server interpolates on its own clock, it keeps running smoothly even when your main thread is busy.</p>
<figure class="td-chart td-chart-line">
<figcaption class="td-chart-caption">A spring overshoots its target, then settles</figcaption>
<div class="td-chart-frame">
<svg
  class="td-chart-svg"
  viewBox="0 0 720 382"
  role="img"
  aria-label="A spring overshoots its target, then settles"
>
<desc>line chart with 0 labels and 1 series</desc>
<line
  class="td-chart-grid"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<text
  class="td-chart-value"
  x="70"
  y="306"
  text-anchor="end"
>0</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="209.33"
  x2="696"
  y2="209.33"
></line>
<text
  class="td-chart-value"
  x="70"
  y="213.33"
  text-anchor="end"
>50</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="116.67"
  x2="696"
  y2="116.67"
></line>
<text
  class="td-chart-value"
  x="70"
  y="120.67"
  text-anchor="end"
>100</text>
<line
  class="td-chart-grid"
  x1="80"
  y1="24"
  x2="696"
  y2="24"
></line>
<text
  class="td-chart-value"
  x="70"
  y="28"
  text-anchor="end"
>150</text>
<line
  class="td-chart-axis"
  x1="80"
  y1="302"
  x2="696"
  y2="302"
></line>
<line
  class="td-chart-axis"
  x1="80"
  y1="24"
  x2="80"
  y2="302"
></line>
<text
  class="td-chart-label"
  x="80"
  y="324"
  text-anchor="middle"
>0</text>
<text
  class="td-chart-label"
  x="388"
  y="324"
  text-anchor="middle"
>4</text>
<text
  class="td-chart-label"
  x="696"
  y="324"
  text-anchor="middle"
>8</text>
<polyline class="td-chart-line td-chart-series-0" points="80,302 157,153.73 234,79.6 311,125.93 388,107.4 465,118.52 542,114.81 619,116.67 696,116.67"></polyline>
<circle
  class="td-chart-point td-chart-series-0"
  cx="80"
  cy="302"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="157"
  cy="153.73"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="234"
  cy="79.6"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="311"
  cy="125.93"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="388"
  cy="107.4"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="465"
  cy="118.52"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="542"
  cy="114.81"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="619"
  cy="116.67"
  r="4"
></circle>
<circle
  class="td-chart-point td-chart-series-0"
  cx="696"
  cy="116.67"
  r="4"
></circle>
<text
  class="td-chart-label"
  x="388"
  y="368"
  text-anchor="middle"
>Time</text>
<text
  class="td-chart-label"
  x="16"
  y="163"
  text-anchor="middle"
  transform="rotate(-90 16 163)"
>Value</text>
<rect
  class="td-chart-series-0"
  x="80"
  y="336"
  width="12"
  height="12"
  rx="3"
  fill="currentColor"
></rect>
<text
  class="td-chart-legend-text"
  x="98"
  y="346"
  text-anchor="start"
>Spring</text>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Spring: (0, 0)</title>
<circle class="td-chart-hit" cx="80" cy="302" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="13.6" y="260" width="132.8" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="22.6" y="280">Spring: (0, 0)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Spring: (1, 80)</title>
<circle class="td-chart-hit" cx="157" cy="153.73" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="86.5" y="111.73" width="141" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="95.5" y="131.73">Spring: (1, 80)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Spring: (2, 120)</title>
<circle class="td-chart-hit" cx="234" cy="79.6" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="159.4" y="37.6" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="168.4" y="57.6">Spring: (2, 120)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Spring: (3, 95)</title>
<circle class="td-chart-hit" cx="311" cy="125.93" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="240.5" y="83.93" width="141" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="249.5" y="103.93">Spring: (3, 95)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Spring: (4, 105)</title>
<circle class="td-chart-hit" cx="388" cy="107.4" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="313.4" y="65.4" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="322.4" y="85.4">Spring: (4, 105)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Spring: (5, 99)</title>
<circle class="td-chart-hit" cx="465" cy="118.52" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="394.5" y="76.52" width="141" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="403.5" y="96.52">Spring: (5, 99)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Spring: (6, 101)</title>
<circle class="td-chart-hit" cx="542" cy="114.81" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="467.4" y="72.81" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="476.4" y="92.81">Spring: (6, 101)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Spring: (7, 100)</title>
<circle class="td-chart-hit" cx="619" cy="116.67" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="544.4" y="74.67" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="553.4" y="94.67">Spring: (7, 100)</text>
</g>
</g>
<g class="td-chart-mark td-chart-series-0" tabindex="0"><title>Spring: (8, 100)</title>
<circle class="td-chart-hit" cx="696" cy="116.67" r="16"></circle>
<g class="td-chart-pop">
<rect class="td-chart-pop-box" x="566.8" y="74.67" width="149.2" height="30" rx="6"></rect>
<text class="td-chart-pop-text" x="575.8" y="94.67">Spring: (8, 100)</text>
</g>
</g>
</svg>
</div>
</figure>
<p>Two lines of math carry the whole motion. The presented value is the start plus the delta, scaled by the curve $p(t)$, which runs from 0 to 1, so the data sits at the target while only the presentation moves:</p>
<div class="td-math td-math-display"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 127.47 11.21" fill="currentColor" aria-hidden="true" style="width:12.75em;height:1.12em;vertical-align:-0.4em"><path d="M5.08 3.2L5.08 2.89C4.85 2.91 4.56 2.92 4.33 2.92L3.46 2.89L3.46 3.2C3.83 3.21 3.94 3.44 3.94 3.63C3.94 3.72 3.92 3.76 3.88 3.87L2.86 6.42L1.74 3.63C1.68 3.5 1.68 3.46 1.68 3.46C1.68 3.2 2.07 3.2 2.25 3.2L2.25 2.89L1.16 2.92C0.89 2.92 0.49 2.91 0.19 2.89L0.19 3.2C0.82 3.2 0.86 3.26 0.99 3.57L2.43 7.12C2.49 7.26 2.51 7.31 2.64 7.31C2.77 7.31 2.81 7.22 2.85 7.12L4.16 3.87C4.25 3.64 4.42 3.21 5.08 3.2Z"/><path d="M8.6 9.58C8.6 9.55 8.58 9.52 8.56 9.5C7.52 8.72 6.83 6.72 6.83 5.12L6.83 4.28C6.83 2.68 7.52 0.68 8.56 -0.1C8.58 -0.12 8.6 -0.15 8.6 -0.18C8.6 -0.23 8.55 -0.28 8.5 -0.28C8.48 -0.28 8.46 -0.27 8.44 -0.26C7.34 0.57 6.29 2.57 6.29 4.28L6.29 5.12C6.29 6.83 7.34 8.83 8.44 9.66C8.46 9.67 8.48 9.68 8.5 9.68C8.55 9.68 8.6 9.63 8.6 9.58Z"/><path d="M12.49 5.96L12.49 5.39L12.24 5.39L12.24 5.94C12.24 6.68 11.94 7.06 11.57 7.06C10.9 7.06 10.9 6.15 10.9 5.98L10.9 3.2L12.33 3.2L12.33 2.89L10.9 2.89L10.9 1.05L10.65 1.05C10.64 1.87 10.34 2.94 9.36 2.98L9.36 3.2L10.21 3.2L10.21 5.96C10.21 7.19 11.14 7.31 11.5 7.31C12.21 7.31 12.49 6.6 12.49 5.96Z"/><path d="M15.94 5.12L15.94 4.28C15.94 2.57 14.89 0.57 13.79 -0.26C13.77 -0.27 13.75 -0.28 13.73 -0.28C13.68 -0.28 13.63 -0.23 13.63 -0.18C13.63 -0.15 13.65 -0.12 13.67 -0.1C14.71 0.68 15.4 2.68 15.4 4.28L15.4 5.12C15.4 6.72 14.71 8.72 13.67 9.5C13.65 9.52 13.63 9.55 13.63 9.58C13.63 9.63 13.68 9.68 13.73 9.68C13.75 9.68 13.77 9.67 13.79 9.66C14.89 8.83 15.94 6.83 15.94 5.12Z"/><path d="M26.95 3.73C26.95 3.62 26.86 3.53 26.75 3.53L20.49 3.53C20.38 3.53 20.29 3.62 20.29 3.73C20.29 3.84 20.38 3.93 20.49 3.93L26.75 3.93C26.86 3.93 26.95 3.84 26.95 3.73ZM26.95 5.67C26.95 5.56 26.86 5.47 26.75 5.47L20.49 5.47C20.38 5.47 20.29 5.56 20.29 5.67C20.29 5.78 20.38 5.87 20.49 5.87L26.75 5.87C26.86 5.87 26.95 5.78 26.95 5.67Z"/><path d="M35.37 3.2L35.37 2.89C35.14 2.91 34.85 2.92 34.62 2.92L33.75 2.89L33.75 3.2C34.12 3.21 34.23 3.44 34.23 3.63C34.23 3.72 34.21 3.76 34.17 3.87L33.15 6.42L32.03 3.63C31.97 3.5 31.97 3.46 31.97 3.46C31.97 3.2 32.36 3.2 32.54 3.2L32.54 2.89L31.45 2.92C31.18 2.92 30.78 2.91 30.48 2.89L30.48 3.2C31.11 3.2 31.15 3.26 31.28 3.57L32.72 7.12C32.78 7.26 32.8 7.31 32.93 7.31C33.06 7.31 33.1 7.22 33.14 7.12L34.45 3.87C34.54 3.64 34.71 3.21 35.37 3.2Z"/><path d="M38.62 5.23C38.62 4.97 38.37 4.73 37.99 4.73C37.5 4.73 36.91 5.11 36.91 5.85L36.91 6.65L36.36 6.65L36.36 6.87L36.91 6.87L36.91 9.14C36.91 9.45 36.83 9.45 36.36 9.45L36.36 9.67L37.16 9.65C37.44 9.65 37.77 9.65 38.05 9.67L38.05 9.45L37.9 9.45C37.39 9.45 37.37 9.38 37.37 9.12L37.37 6.87L38.17 6.87L38.17 6.65L37.35 6.65L37.35 5.84C37.35 5.23 37.69 4.89 37.99 4.89C38.02 4.89 38.12 4.89 38.23 4.94C38.14 4.97 38.02 5.06 38.02 5.23C38.02 5.39 38.13 5.53 38.32 5.53C38.52 5.53 38.62 5.39 38.62 5.23Z"/><path d="M40.82 7C40.82 6.78 40.6 6.58 40.3 6.58C39.79 6.58 39.53 7.05 39.44 7.35L39.44 6.58L38.46 6.65L38.46 6.87C38.95 6.87 39.01 6.92 39.01 7.26L39.01 9.14C39.01 9.45 38.93 9.45 38.46 9.45L38.46 9.67L39.26 9.65C39.54 9.65 39.87 9.65 40.15 9.67L40.15 9.45L40 9.45C39.49 9.45 39.47 9.38 39.47 9.12L39.47 8.05C39.47 7.35 39.77 6.73 40.3 6.73C40.35 6.73 40.36 6.73 40.37 6.74C40.35 6.74 40.21 6.83 40.21 7.01C40.21 7.21 40.36 7.31 40.51 7.31C40.64 7.31 40.82 7.23 40.82 7Z"/><path d="M44.31 8.17C44.31 7.28 43.61 6.53 42.76 6.53C41.89 6.53 41.21 7.3 41.21 8.17C41.21 9.07 41.94 9.75 42.75 9.75C43.6 9.75 44.31 9.06 44.31 8.17ZM43.73 8.12C43.73 8.37 43.73 8.75 43.57 9.05C43.42 9.37 43.11 9.57 42.76 9.57C42.46 9.57 42.15 9.43 41.96 9.1C41.79 8.8 41.79 8.37 41.79 8.12C41.79 7.84 41.79 7.47 41.96 7.16C42.15 6.84 42.47 6.69 42.75 6.69C43.06 6.69 43.36 6.84 43.55 7.14C43.73 7.44 43.73 7.85 43.73 8.12Z"/><path d="M50.2 9.67L50.2 9.45C49.84 9.45 49.66 9.45 49.66 9.24L49.66 7.91C49.66 7.3 49.66 7.09 49.44 6.84C49.34 6.72 49.11 6.58 48.7 6.58C48.12 6.58 47.81 7 47.69 7.26C47.59 6.65 47.07 6.58 46.76 6.58C46.25 6.58 45.92 6.88 45.72 7.31L45.72 6.58L44.74 6.65L44.74 6.87C45.23 6.87 45.28 6.92 45.28 7.26L45.28 9.14C45.28 9.45 45.2 9.45 44.74 9.45L44.74 9.67L45.53 9.65L46.31 9.67L46.31 9.45C45.84 9.45 45.76 9.45 45.76 9.14L45.76 7.85C45.76 7.12 46.26 6.73 46.71 6.73C47.15 6.73 47.23 7.11 47.23 7.51L47.23 9.14C47.23 9.45 47.15 9.45 46.68 9.45L46.68 9.67L47.47 9.65L48.26 9.67L48.26 9.45C47.79 9.45 47.71 9.45 47.71 9.14L47.71 7.85C47.71 7.12 48.21 6.73 48.66 6.73C49.1 6.73 49.17 7.11 49.17 7.51L49.17 9.14C49.17 9.45 49.1 9.45 48.63 9.45L48.63 9.67L49.42 9.65Z"/><path d="M59.78 4.7C59.78 4.59 59.69 4.5 59.58 4.5L56.65 4.5L56.65 1.57C56.65 1.46 56.56 1.37 56.45 1.37C56.34 1.37 56.25 1.46 56.25 1.57L56.25 4.5L53.32 4.5C53.21 4.5 53.12 4.59 53.12 4.7C53.12 4.81 53.21 4.9 53.32 4.9L56.25 4.9L56.25 7.83C56.25 7.94 56.34 8.03 56.45 8.03C56.56 8.03 56.65 7.94 56.65 7.83L56.65 4.9L59.58 4.9C59.69 4.9 59.78 4.81 59.78 4.7Z"/><path d="M65.89 9.58C65.89 9.55 65.87 9.52 65.85 9.5C64.81 8.72 64.12 6.72 64.12 5.12L64.12 4.28C64.12 2.68 64.81 0.68 65.85 -0.1C65.87 -0.12 65.89 -0.15 65.89 -0.18C65.89 -0.23 65.84 -0.28 65.79 -0.28C65.77 -0.28 65.75 -0.27 65.73 -0.26C64.63 0.57 63.58 2.57 63.58 4.28L63.58 5.12C63.58 6.83 64.63 8.83 65.73 9.66C65.75 9.67 65.77 9.68 65.79 9.68C65.84 9.68 65.89 9.63 65.89 9.58Z"/><path d="M71.54 3.2L71.54 2.89C71.31 2.91 71.02 2.92 70.79 2.92L69.92 2.89L69.92 3.2C70.29 3.21 70.4 3.44 70.4 3.63C70.4 3.72 70.38 3.76 70.34 3.87L69.32 6.42L68.2 3.63C68.14 3.5 68.14 3.46 68.14 3.46C68.14 3.2 68.53 3.2 68.71 3.2L68.71 2.89L67.62 2.92C67.35 2.92 66.95 2.91 66.65 2.89L66.65 3.2C67.28 3.2 67.32 3.26 67.45 3.57L68.89 7.12C68.95 7.26 68.97 7.31 69.1 7.31C69.23 7.31 69.27 7.22 69.31 7.12L70.62 3.87C70.71 3.64 70.88 3.21 71.54 3.2Z"/><path d="M74.62 8.8L74.62 8.4L74.45 8.4L74.45 8.79C74.45 9.31 74.24 9.57 73.98 9.57C73.51 9.57 73.51 8.94 73.51 8.82L73.51 6.87L74.51 6.87L74.51 6.65L73.51 6.65L73.51 5.37L73.33 5.37C73.33 5.94 73.12 6.69 72.43 6.72L72.43 6.87L73.02 6.87L73.02 8.8C73.02 9.66 73.68 9.75 73.93 9.75C74.43 9.75 74.62 9.25 74.62 8.8Z"/><path d="M78.32 8.17C78.32 7.28 77.62 6.53 76.77 6.53C75.9 6.53 75.22 7.3 75.22 8.17C75.22 9.07 75.94 9.75 76.76 9.75C77.61 9.75 78.32 9.06 78.32 8.17ZM77.74 8.12C77.74 8.37 77.74 8.75 77.58 9.05C77.43 9.37 77.12 9.57 76.77 9.57C76.47 9.57 76.16 9.43 75.97 9.1C75.8 8.8 75.8 8.37 75.8 8.12C75.8 7.84 75.8 7.47 75.96 7.16C76.15 6.84 76.48 6.69 76.76 6.69C77.07 6.69 77.37 6.84 77.55 7.14C77.74 7.44 77.74 7.85 77.74 8.12Z"/><path d="M83.5 5.33L83.5 4.75L80.85 4.75L80.85 5.33Z"/><path d="M91.37 3.2L91.37 2.89C91.14 2.91 90.85 2.92 90.62 2.92L89.75 2.89L89.75 3.2C90.12 3.21 90.23 3.44 90.23 3.63C90.23 3.72 90.21 3.76 90.17 3.87L89.15 6.42L88.03 3.63C87.97 3.5 87.97 3.46 87.97 3.46C87.97 3.2 88.36 3.2 88.54 3.2L88.54 2.89L87.45 2.92C87.18 2.92 86.78 2.91 86.48 2.89L86.48 3.2C87.11 3.2 87.15 3.26 87.28 3.57L88.72 7.12C88.78 7.26 88.8 7.31 88.93 7.31C89.06 7.31 89.1 7.22 89.14 7.12L90.45 3.87C90.54 3.64 90.71 3.21 91.37 3.2Z"/><path d="M94.63 5.23C94.63 4.97 94.37 4.73 94 4.73C93.51 4.73 92.92 5.11 92.92 5.85L92.92 6.65L92.37 6.65L92.37 6.87L92.92 6.87L92.92 9.14C92.92 9.45 92.84 9.45 92.37 9.45L92.37 9.67L93.17 9.65C93.45 9.65 93.78 9.65 94.06 9.67L94.06 9.45L93.91 9.45C93.39 9.45 93.38 9.38 93.38 9.12L93.38 6.87L94.18 6.87L94.18 6.65L93.36 6.65L93.36 5.84C93.36 5.23 93.7 4.89 94 4.89C94.02 4.89 94.13 4.89 94.23 4.94C94.15 4.97 94.02 5.06 94.02 5.23C94.02 5.39 94.14 5.53 94.33 5.53C94.53 5.53 94.63 5.39 94.63 5.23Z"/><path d="M96.82 7C96.82 6.78 96.61 6.58 96.31 6.58C95.8 6.58 95.54 7.05 95.45 7.35L95.45 6.58L94.47 6.65L94.47 6.87C94.96 6.87 95.02 6.92 95.02 7.26L95.02 9.14C95.02 9.45 94.94 9.45 94.47 9.45L94.47 9.67L95.27 9.65C95.55 9.65 95.88 9.65 96.16 9.67L96.16 9.45L96.01 9.45C95.49 9.45 95.48 9.38 95.48 9.12L95.48 8.05C95.48 7.35 95.77 6.73 96.31 6.73C96.36 6.73 96.37 6.73 96.38 6.74C96.36 6.74 96.22 6.83 96.22 7.01C96.22 7.21 96.37 7.31 96.52 7.31C96.65 7.31 96.82 7.23 96.82 7Z"/><path d="M100.32 8.17C100.32 7.28 99.62 6.53 98.77 6.53C97.9 6.53 97.22 7.3 97.22 8.17C97.22 9.07 97.94 9.75 98.76 9.75C99.61 9.75 100.32 9.06 100.32 8.17ZM99.74 8.12C99.74 8.37 99.74 8.75 99.58 9.05C99.43 9.37 99.12 9.57 98.77 9.57C98.47 9.57 98.16 9.43 97.97 9.1C97.8 8.8 97.8 8.37 97.8 8.12C97.8 7.84 97.8 7.47 97.97 7.16C98.15 6.84 98.48 6.69 98.76 6.69C99.07 6.69 99.37 6.84 99.55 7.14C99.74 7.44 99.74 7.85 99.74 8.12Z"/><path d="M106.21 9.67L106.21 9.45C105.85 9.45 105.67 9.45 105.67 9.24L105.67 7.91C105.67 7.3 105.67 7.09 105.45 6.84C105.35 6.72 105.12 6.58 104.71 6.58C104.13 6.58 103.82 7 103.7 7.26C103.6 6.65 103.08 6.58 102.77 6.58C102.26 6.58 101.93 6.88 101.73 7.31L101.73 6.58L100.74 6.65L100.74 6.87C101.23 6.87 101.29 6.92 101.29 7.26L101.29 9.14C101.29 9.45 101.21 9.45 100.74 9.45L100.74 9.67L101.54 9.65L102.32 9.67L102.32 9.45C101.85 9.45 101.77 9.45 101.77 9.14L101.77 7.85C101.77 7.12 102.27 6.73 102.72 6.73C103.16 6.73 103.24 7.11 103.24 7.51L103.24 9.14C103.24 9.45 103.16 9.45 102.69 9.45L102.69 9.67L103.48 9.65L104.27 9.67L104.27 9.45C103.8 9.45 103.72 9.45 103.72 9.14L103.72 7.85C103.72 7.12 104.22 6.73 104.66 6.73C105.11 6.73 105.18 7.11 105.18 7.51L105.18 9.14C105.18 9.45 105.11 9.45 104.64 9.45L104.64 9.67L105.43 9.65Z"/><path d="M109.23 5.12L109.23 4.28C109.23 2.57 108.18 0.57 107.08 -0.26C107.06 -0.27 107.04 -0.28 107.02 -0.28C106.97 -0.28 106.92 -0.23 106.92 -0.18C106.92 -0.15 106.94 -0.12 106.96 -0.1C108 0.68 108.69 2.68 108.69 4.28L108.69 5.12C108.69 6.72 108 8.72 106.96 9.5C106.94 9.52 106.92 9.55 106.92 9.58C106.92 9.63 106.97 9.68 107.02 9.68C107.04 9.68 107.06 9.67 107.08 9.66C108.18 8.83 109.23 6.83 109.23 5.12Z"/><path d="M115.45 5.04C115.45 3.77 114.48 2.78 113.36 2.78C112.58 2.78 112.16 3.22 111.96 3.44L111.96 2.78L110.52 2.89L110.52 3.2C111.23 3.2 111.3 3.26 111.3 3.7L111.3 8.38C111.3 8.83 111.19 8.83 110.52 8.83L110.52 9.14L111.64 9.11L112.77 9.14L112.77 8.83C112.1 8.83 111.99 8.83 111.99 8.38L111.99 6.7L111.99 6.61C112.04 6.77 112.46 7.31 113.22 7.31C114.41 7.31 115.45 6.33 115.45 5.04ZM114.62 5.04C114.62 6.25 113.92 7.09 113.18 7.09C112.78 7.09 112.4 6.89 112.13 6.48C111.99 6.27 111.99 6.26 111.99 6.06L111.99 3.83C112.28 3.32 112.77 3.03 113.28 3.03C114.01 3.03 114.62 3.91 114.62 5.04Z"/><path d="M119.12 9.58C119.12 9.55 119.1 9.52 119.08 9.5C118.04 8.72 117.35 6.72 117.35 5.12L117.35 4.28C117.35 2.68 118.04 0.68 119.08 -0.1C119.1 -0.12 119.12 -0.15 119.12 -0.18C119.12 -0.23 119.07 -0.28 119.02 -0.28C119 -0.28 118.98 -0.27 118.96 -0.26C117.86 0.57 116.81 2.57 116.81 4.28L116.81 5.12C116.81 6.83 117.86 8.83 118.96 9.66C118.98 9.67 119 9.68 119.02 9.68C119.07 9.68 119.12 9.63 119.12 9.58Z"/><path d="M123.01 5.96L123.01 5.39L122.76 5.39L122.76 5.94C122.76 6.68 122.46 7.06 122.09 7.06C121.42 7.06 121.42 6.15 121.42 5.98L121.42 3.2L122.85 3.2L122.85 2.89L121.42 2.89L121.42 1.05L121.17 1.05C121.16 1.87 120.86 2.94 119.88 2.98L119.88 3.2L120.73 3.2L120.73 5.96C120.73 7.19 121.66 7.31 122.02 7.31C122.73 7.31 123.01 6.6 123.01 5.96Z"/><path d="M126.46 5.12L126.46 4.28C126.46 2.57 125.41 0.57 124.31 -0.26C124.29 -0.27 124.27 -0.28 124.25 -0.28C124.2 -0.28 124.15 -0.23 124.15 -0.18C124.15 -0.15 124.17 -0.12 124.19 -0.1C125.23 0.68 125.92 2.68 125.92 4.28L125.92 5.12C125.92 6.72 125.23 8.72 124.19 9.5C124.17 9.52 124.15 9.55 124.15 9.58C124.15 9.63 124.2 9.68 124.25 9.68C124.27 9.68 124.29 9.67 124.31 9.66C125.41 8.83 126.46 6.83 126.46 5.12Z"/></svg><math class="td-math-a11y" xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi>v</mi><mtext>(</mtext><mi>t</mi><mtext>)</mtext><mtext> </mtext><mtext>=</mtext><mtext> </mtext><msub><mrow><mi>v</mi></mrow><mrow><mrow><mi>f</mi><mi>r</mi><mi>o</mi><mi>m</mi></mrow></mrow></msub><mtext> </mtext><mtext>+</mtext><mtext> </mtext><mtext>(</mtext><msub><mrow><mi>v</mi></mrow><mrow><mrow><mi>t</mi><mi>o</mi></mrow></mrow></msub><mtext> </mtext><mtext>-</mtext><mtext> </mtext><msub><mrow><mi>v</mi></mrow><mrow><mrow><mi>f</mi><mi>r</mi><mi>o</mi><mi>m</mi></mrow></mrow></msub><mtext>)</mtext><mtext> </mtext><mi>p</mi><mtext>(</mtext><mi>t</mi><mtext>)</mtext></mrow></math></div>
<p>A spring is the same machinery with the curve replaced by a damped harmonic oscillator. Released from rest, its progress curve is</p>
<div class="td-math td-math-display"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 171.94 21.18" fill="currentColor" aria-hidden="true" style="width:17.19em;height:2.12em;vertical-align:-0.81em"><path d="M5.21 10.93C5.21 9.66 4.24 8.67 3.12 8.67C2.34 8.67 1.92 9.11 1.72 9.33L1.72 8.67L0.28 8.78L0.28 9.09C0.99 9.09 1.06 9.15 1.06 9.59L1.06 14.27C1.06 14.72 0.95 14.72 0.28 14.72L0.28 15.03L1.4 15L2.53 15.03L2.53 14.72C1.86 14.72 1.75 14.72 1.75 14.27L1.75 12.59L1.75 12.5C1.8 12.66 2.22 13.2 2.98 13.2C4.17 13.2 5.21 12.22 5.21 10.93ZM4.38 10.93C4.38 12.14 3.68 12.98 2.94 12.98C2.54 12.98 2.16 12.78 1.89 12.37C1.75 12.16 1.75 12.15 1.75 11.95L1.75 9.72C2.04 9.21 2.53 8.92 3.04 8.92C3.77 8.92 4.38 9.8 4.38 10.93Z"/><path d="M8.88 15.47C8.88 15.44 8.86 15.41 8.84 15.39C7.8 14.61 7.11 12.61 7.11 11.01L7.11 10.17C7.11 8.57 7.8 6.57 8.84 5.79C8.86 5.77 8.88 5.74 8.88 5.71C8.88 5.66 8.83 5.61 8.78 5.61C8.76 5.61 8.74 5.62 8.72 5.63C7.62 6.46 6.57 8.46 6.57 10.17L6.57 11.01C6.57 12.72 7.62 14.72 8.72 15.55C8.74 15.56 8.76 15.57 8.78 15.57C8.83 15.57 8.88 15.52 8.88 15.47Z"/><path d="M12.77 11.85L12.77 11.28L12.52 11.28L12.52 11.83C12.52 12.57 12.22 12.95 11.85 12.95C11.18 12.95 11.18 12.04 11.18 11.87L11.18 9.09L12.61 9.09L12.61 8.78L11.18 8.78L11.18 6.94L10.93 6.94C10.92 7.76 10.62 8.83 9.64 8.87L9.64 9.09L10.49 9.09L10.49 11.85C10.49 13.08 11.42 13.2 11.78 13.2C12.49 13.2 12.77 12.49 12.77 11.85Z"/><path d="M16.22 11.01L16.22 10.17C16.22 8.46 15.17 6.46 14.07 5.63C14.05 5.62 14.03 5.61 14.01 5.61C13.96 5.61 13.91 5.66 13.91 5.71C13.91 5.74 13.93 5.77 13.95 5.79C14.99 6.57 15.68 8.57 15.68 10.17L15.68 11.01C15.68 12.61 14.99 14.61 13.95 15.39C13.93 15.41 13.91 15.44 13.91 15.47C13.91 15.52 13.96 15.57 14.01 15.57C14.03 15.57 14.05 15.56 14.07 15.55C15.17 14.72 16.22 12.72 16.22 11.01Z"/><path d="M27.23 9.62C27.23 9.51 27.14 9.42 27.03 9.42L20.77 9.42C20.66 9.42 20.57 9.51 20.57 9.62C20.57 9.73 20.66 9.82 20.77 9.82L27.03 9.82C27.14 9.82 27.23 9.73 27.23 9.62ZM27.23 11.56C27.23 11.45 27.14 11.36 27.03 11.36L20.77 11.36C20.66 11.36 20.57 11.45 20.57 11.56C20.57 11.67 20.66 11.76 20.77 11.76L27.03 11.76C27.14 11.76 27.23 11.67 27.23 11.56Z"/><path d="M34.76 13.09L34.76 12.78L34.44 12.78C33.54 12.78 33.51 12.67 33.51 12.3L33.51 6.69C33.51 6.45 33.51 6.43 33.28 6.43C32.66 7.07 31.78 7.07 31.46 7.07L31.46 7.38C31.66 7.38 32.25 7.38 32.77 7.12L32.77 12.3C32.77 12.66 32.74 12.78 31.84 12.78L31.52 12.78L31.52 13.09C31.87 13.06 32.74 13.06 33.14 13.06C33.54 13.06 34.41 13.06 34.76 13.09Z"/><path d="M40.55 11.22L40.55 10.64L37.9 10.64L37.9 11.22Z"/><path d="M47.49 11.9C47.49 11.8 47.41 11.78 47.36 11.78C47.27 11.78 47.25 11.84 47.23 11.92C46.88 12.95 45.98 12.95 45.88 12.95C45.38 12.95 44.98 12.65 44.75 12.28C44.45 11.8 44.45 11.14 44.45 10.78L47.24 10.78C47.46 10.78 47.49 10.78 47.49 10.57C47.49 9.58 46.95 8.61 45.7 8.61C44.54 8.61 43.62 9.64 43.62 10.89C43.62 12.23 44.67 13.2 45.82 13.2C47.04 13.2 47.49 12.09 47.49 11.9ZM46.83 10.57L44.46 10.57C44.52 9.08 45.36 8.83 45.7 8.83C46.73 8.83 46.83 10.18 46.83 10.57Z"/><path d="M50.27 8.15L50.27 7.75L48.42 7.75L48.42 8.15Z"/><path d="M54.06 10.05C53.99 9.78 53.82 9.64 53.75 9.58C53.6 9.45 53.46 9.41 53.01 9.27C52.4 9.08 52.28 9.04 52.08 8.9C51.71 8.63 51.62 8.23 51.58 8.1C51.32 7.01 51.86 5.79 52.47 5.41C52.63 5.54 52.79 5.54 52.93 5.54C53.11 5.54 53.56 5.54 53.5 5.32C53.46 5.14 53.17 5.13 52.89 5.13C52.81 5.13 52.62 5.13 52.46 5.2C52.41 5.12 52.39 5.08 52.34 4.93C52.32 4.84 52.32 4.67 52.32 4.67C52.3 4.62 52.26 4.58 52.21 4.58C52.09 4.58 52.16 4.91 52.17 4.93C52.2 5.05 52.25 5.17 52.34 5.28C51.69 5.65 50.91 6.94 51.25 8.29C51.5 9.28 52.18 9.49 52.73 9.66C52.96 9.74 52.97 9.74 53.19 9.81C53.35 9.85 53.66 9.95 53.74 10.28C53.79 10.47 53.73 10.74 53.47 10.74C53.29 10.74 53.08 10.66 52.9 10.53C52.84 10.49 52.83 10.48 52.8 10.48C52.76 10.48 52.74 10.51 52.75 10.56C52.77 10.63 53.14 10.9 53.51 10.9C53.94 10.9 54.16 10.45 54.06 10.05ZM53.32 5.33C53.27 5.35 53.21 5.38 52.9 5.38C52.75 5.38 52.7 5.38 52.62 5.33C52.71 5.28 52.83 5.28 52.93 5.28C53.16 5.28 53.18 5.29 53.32 5.33Z"/><path d="M58.55 7.79C58.56 7.49 58.55 7.14 58.48 6.86C58.44 6.68 58.36 6.52 58.24 6.43C58.18 6.39 58.13 6.37 58.06 6.37C57.98 6.37 57.9 6.41 57.85 6.48C57.8 6.55 57.78 6.63 57.8 6.7C57.82 6.77 57.86 6.83 57.92 6.88C58.13 7.03 58.28 7.25 58.34 7.5C58.36 7.58 58.38 7.67 58.38 7.75C58.38 8.39 58.13 9.04 57.58 9.04C57.19 9.04 56.89 8.77 56.73 8.41C56.78 8.21 56.8 8 56.79 7.79C56.79 7.73 56.79 7.66 56.78 7.61C56.75 7.5 56.69 7.43 56.59 7.43C56.46 7.43 56.44 7.6 56.44 7.75C56.44 7.97 56.46 8.18 56.51 8.38C56.37 8.76 56.1 9.04 55.72 9.04C55.29 9.04 55.02 8.69 54.91 8.24C54.88 8.1 54.86 7.94 54.85 7.79C54.85 7.37 55 6.98 55.18 6.61C55.19 6.58 55.2 6.54 55.19 6.52C55.18 6.47 55.14 6.44 55.1 6.42C55.08 6.4 55.06 6.4 55.04 6.4C55 6.4 54.96 6.42 54.93 6.47C54.74 6.87 54.68 7.31 54.68 7.75C54.68 8.02 54.7 8.29 54.77 8.54C54.91 9.11 55.22 9.54 55.75 9.54C56.19 9.54 56.48 9.23 56.64 8.8C56.82 9.23 57.15 9.54 57.62 9.54C58.34 9.54 58.56 8.64 58.55 7.79Z"/><path d="M61.51 9.62C61.51 9.23 61.49 8.84 61.32 8.48C61.09 8.01 60.69 7.93 60.49 7.93C60.19 7.93 59.83 8.06 59.63 8.51C59.48 8.85 59.45 9.23 59.45 9.62C59.45 9.99 59.47 10.43 59.67 10.8C59.88 11.2 60.24 11.3 60.48 11.3C60.74 11.3 61.12 11.2 61.33 10.73C61.49 10.39 61.51 10.01 61.51 9.62ZM61.11 9.56C61.11 9.93 61.11 10.27 61.05 10.58C60.98 11.04 60.7 11.19 60.48 11.19C60.29 11.19 60 11.07 59.91 10.6C59.86 10.3 59.86 9.85 59.86 9.56C59.86 9.25 59.86 8.93 59.9 8.66C59.99 8.08 60.36 8.04 60.48 8.04C60.64 8.04 60.97 8.12 61.06 8.61C61.11 8.88 61.11 9.26 61.11 9.56Z"/><path d="M64.03 8.59L64.03 8.2L63.86 8.2L63.86 8.58C63.86 9.1 63.65 9.36 63.39 9.36C62.92 9.36 62.92 8.73 62.92 8.61L62.92 6.66L63.92 6.66L63.92 6.45L62.92 6.45L62.92 5.16L62.75 5.16C62.74 5.73 62.53 6.48 61.84 6.51L61.84 6.66L62.44 6.66L62.44 8.59C62.44 9.46 63.09 9.54 63.34 9.54C63.84 9.54 64.03 9.04 64.03 8.59Z"/><path d="M66.99 15.39C66.99 15.28 66.9 15.19 66.79 15.19L65.97 15.19L65.97 5.99L66.79 5.99C66.9 5.99 66.99 5.9 66.99 5.79C66.99 5.68 66.9 5.59 66.79 5.59L65.57 5.59L65.57 15.59L66.79 15.59C66.9 15.59 66.99 15.5 66.99 15.39Z"/><path d="M71.36 11.9C71.36 11.8 71.26 11.8 71.23 11.8C71.14 11.8 71.12 11.84 71.1 11.9C70.81 12.83 70.16 12.95 69.79 12.95C69.26 12.95 68.38 12.52 68.38 10.91C68.38 9.28 69.2 8.86 69.73 8.86C69.82 8.86 70.45 8.87 70.8 9.23C70.39 9.26 70.33 9.56 70.33 9.69C70.33 9.95 70.51 10.15 70.79 10.15C71.05 10.15 71.25 9.98 71.25 9.68C71.25 9 70.49 8.61 69.72 8.61C68.47 8.61 67.55 9.69 67.55 10.93C67.55 12.21 68.54 13.2 69.7 13.2C71.04 13.2 71.36 12 71.36 11.9Z"/><path d="M76.36 10.95C76.36 9.67 75.36 8.61 74.15 8.61C72.9 8.61 71.93 9.7 71.93 10.95C71.93 12.24 72.97 13.2 74.14 13.2C75.35 13.2 76.36 12.22 76.36 10.95ZM75.53 10.87C75.53 11.23 75.53 11.77 75.31 12.21C75.09 12.66 74.65 12.95 74.15 12.95C73.72 12.95 73.28 12.74 73.01 12.28C72.76 11.84 72.76 11.23 72.76 10.87C72.76 10.48 72.76 9.94 73 9.5C73.27 9.04 73.74 8.83 74.14 8.83C74.58 8.83 75.01 9.05 75.27 9.48C75.53 9.91 75.53 10.49 75.53 10.87Z"/><path d="M80.25 11.81C80.25 11.28 79.95 10.98 79.83 10.86C79.5 10.54 79.11 10.46 78.69 10.38C78.13 10.27 77.46 10.14 77.46 9.56C77.46 9.21 77.72 8.8 78.58 8.8C79.68 8.8 79.73 9.7 79.75 10.01C79.76 10.1 79.87 10.1 79.87 10.1C80 10.1 80 10.05 80 9.86L80 8.85C80 8.68 80 8.61 79.89 8.61C79.84 8.61 79.82 8.61 79.69 8.73C79.66 8.77 79.56 8.86 79.52 8.89C79.14 8.61 78.73 8.61 78.58 8.61C77.36 8.61 76.98 9.28 76.98 9.84C76.98 10.19 77.14 10.47 77.41 10.69C77.73 10.95 78.01 11.01 78.73 11.15C78.95 11.19 79.77 11.35 79.77 12.07C79.77 12.58 79.42 12.98 78.64 12.98C77.8 12.98 77.44 12.41 77.25 11.56C77.22 11.43 77.21 11.39 77.11 11.39C76.98 11.39 76.98 11.46 76.98 11.64L76.98 12.96C76.98 13.13 76.98 13.2 77.09 13.2C77.14 13.2 77.15 13.19 77.34 13C77.36 12.98 77.36 12.96 77.54 12.77C77.98 13.19 78.43 13.2 78.64 13.2C79.79 13.2 80.25 12.53 80.25 11.81Z"/><path d="M83.91 15.47C83.91 15.44 83.89 15.41 83.87 15.39C82.83 14.61 82.14 12.61 82.14 11.01L82.14 10.17C82.14 8.57 82.83 6.57 83.87 5.79C83.89 5.77 83.91 5.74 83.91 5.71C83.91 5.66 83.86 5.61 83.81 5.61C83.79 5.61 83.77 5.62 83.75 5.63C82.65 6.46 81.6 8.46 81.6 10.17L81.6 11.01C81.6 12.72 82.65 14.72 83.75 15.55C83.77 15.56 83.79 15.57 83.81 15.57C83.86 15.57 83.91 15.52 83.91 15.47Z"/><path d="M90.44 10.7C90.45 10.27 90.44 9.77 90.34 9.37C90.28 9.11 90.17 8.89 89.99 8.76C89.91 8.7 89.83 8.67 89.74 8.67C89.62 8.67 89.5 8.73 89.43 8.83C89.36 8.93 89.34 9.04 89.37 9.15C89.39 9.25 89.45 9.33 89.54 9.4C89.84 9.62 90.05 9.93 90.14 10.28C90.17 10.4 90.19 10.53 90.19 10.65C90.19 11.56 89.84 12.48 89.05 12.48C88.49 12.48 88.06 12.1 87.84 11.58C87.9 11.3 87.93 11 87.92 10.7C87.92 10.61 87.92 10.52 87.9 10.44C87.86 10.29 87.78 10.18 87.64 10.18C87.45 10.18 87.42 10.43 87.42 10.65C87.42 10.96 87.45 11.26 87.52 11.55C87.32 12.09 86.94 12.48 86.39 12.48C85.78 12.48 85.39 11.98 85.24 11.35C85.19 11.15 85.16 10.92 85.15 10.7C85.15 10.1 85.37 9.54 85.62 9.01C85.64 8.97 85.65 8.92 85.64 8.88C85.62 8.82 85.57 8.77 85.51 8.74C85.48 8.72 85.45 8.72 85.42 8.72C85.36 8.72 85.3 8.75 85.26 8.81C84.99 9.38 84.9 10.02 84.9 10.65C84.9 11.03 84.94 11.42 85.03 11.77C85.23 12.58 85.68 13.2 86.44 13.2C87.07 13.2 87.48 12.76 87.7 12.14C87.97 12.76 88.43 13.2 89.1 13.2C90.14 13.2 90.45 11.91 90.44 10.7Z"/><path d="M95.14 15.56L95.14 15.35C94.65 15.35 94.6 15.3 94.6 14.95L94.6 10.7L93.59 10.78L93.59 11C94.08 11 94.13 11.05 94.13 11.39L94.13 12.9C93.93 12.65 93.63 12.47 93.25 12.47C92.43 12.47 91.69 13.15 91.69 14.06C91.69 14.95 92.38 15.64 93.18 15.64C93.62 15.64 93.94 15.4 94.11 15.18L94.11 15.64ZM94.11 14.74C94.11 14.86 94.11 14.88 94.04 15C93.83 15.33 93.51 15.49 93.21 15.49C92.9 15.49 92.64 15.3 92.48 15.04C92.29 14.75 92.27 14.35 92.27 14.06C92.27 13.81 92.29 13.39 92.49 13.07C92.64 12.85 92.9 12.62 93.28 12.62C93.53 12.62 93.82 12.73 94.04 13.04C94.11 13.16 94.11 13.18 94.11 13.3Z"/><path d="M98.67 11.85L98.67 11.28L98.42 11.28L98.42 11.83C98.42 12.57 98.12 12.95 97.75 12.95C97.08 12.95 97.08 12.04 97.08 11.87L97.08 9.09L98.51 9.09L98.51 8.78L97.08 8.78L97.08 6.94L96.83 6.94C96.82 7.76 96.52 8.83 95.54 8.87L95.54 9.09L96.39 9.09L96.39 11.85C96.39 13.08 97.32 13.2 97.68 13.2C98.39 13.2 98.67 12.49 98.67 11.85Z"/><path d="M102.12 11.01L102.12 10.17C102.12 8.46 101.07 6.46 99.97 5.63C99.95 5.62 99.93 5.61 99.91 5.61C99.86 5.61 99.81 5.66 99.81 5.71C99.81 5.74 99.83 5.77 99.85 5.79C100.89 6.57 101.58 8.57 101.58 10.17L101.58 11.01C101.58 12.61 100.89 14.61 99.85 15.39C99.83 15.41 99.81 15.44 99.81 15.47C99.81 15.52 99.86 15.57 99.91 15.57C99.93 15.57 99.95 15.56 99.97 15.55C101.07 14.72 102.12 12.72 102.12 11.01Z"/><path d="M112.57 10.59C112.57 10.48 112.48 10.39 112.37 10.39L109.44 10.39L109.44 7.46C109.44 7.35 109.35 7.26 109.24 7.26C109.13 7.26 109.04 7.35 109.04 7.46L109.04 10.39L106.11 10.39C106 10.39 105.91 10.48 105.91 10.59C105.91 10.7 106 10.79 106.11 10.79L109.04 10.79L109.04 13.72C109.04 13.83 109.13 13.92 109.24 13.92C109.35 13.92 109.44 13.83 109.44 13.72L109.44 10.79L112.37 10.79C112.48 10.79 112.57 10.7 112.57 10.59Z"/><rect x="115.35" y="10.39" width="17.33" height="0.4"/><path d="M121.52 6.59C121.44 6.28 121.24 6.11 121.16 6.04C120.99 5.89 120.81 5.84 120.29 5.67C119.57 5.45 119.44 5.41 119.2 5.24C118.77 4.93 118.66 4.46 118.62 4.3C118.3 3.03 118.94 1.6 119.66 1.16C119.85 1.3 120.03 1.3 120.2 1.3C120.4 1.3 120.93 1.3 120.86 1.05C120.81 0.84 120.48 0.83 120.15 0.83C120.06 0.83 119.84 0.83 119.65 0.91C119.58 0.81 119.56 0.77 119.51 0.6C119.48 0.48 119.48 0.3 119.48 0.3C119.46 0.23 119.41 0.19 119.35 0.19C119.21 0.19 119.3 0.57 119.3 0.59C119.34 0.73 119.4 0.88 119.5 1C118.75 1.43 117.83 2.94 118.22 4.53C118.52 5.69 119.32 5.94 119.96 6.13C120.23 6.22 120.25 6.22 120.5 6.31C120.69 6.36 121.05 6.48 121.15 6.86C121.21 7.08 121.13 7.4 120.83 7.4C120.62 7.4 120.37 7.31 120.16 7.16C120.09 7.11 120.08 7.1 120.04 7.1C120 7.1 119.97 7.13 119.98 7.19C120.01 7.27 120.44 7.58 120.87 7.58C121.38 7.58 121.63 7.06 121.52 6.59ZM120.65 1.06C120.59 1.08 120.52 1.12 120.16 1.12C119.98 1.12 119.93 1.12 119.83 1.07C119.94 1.01 120.08 1.01 120.19 1.01C120.46 1.01 120.49 1.02 120.65 1.06Z"/><path d="M126.78 3.94C126.79 3.59 126.78 3.18 126.7 2.85C126.65 2.64 126.56 2.46 126.41 2.35C126.35 2.3 126.28 2.28 126.21 2.28C126.11 2.28 126.01 2.33 125.95 2.41C125.9 2.49 125.88 2.58 125.91 2.67C125.92 2.76 125.97 2.82 126.04 2.88C126.29 3.06 126.46 3.31 126.54 3.6C126.56 3.7 126.58 3.8 126.58 3.9C126.58 4.65 126.29 5.4 125.64 5.4C125.18 5.4 124.83 5.09 124.65 4.67C124.7 4.44 124.72 4.19 124.72 3.94C124.72 3.87 124.72 3.8 124.7 3.73C124.67 3.61 124.6 3.52 124.49 3.52C124.33 3.52 124.31 3.72 124.31 3.9C124.31 4.16 124.33 4.4 124.39 4.64C124.22 5.08 123.91 5.4 123.46 5.4C122.96 5.4 122.64 4.99 122.52 4.48C122.48 4.31 122.45 4.12 122.44 3.94C122.44 3.45 122.63 2.99 122.83 2.56C122.85 2.53 122.85 2.48 122.85 2.45C122.83 2.4 122.79 2.36 122.74 2.34C122.72 2.32 122.69 2.32 122.67 2.32C122.62 2.32 122.57 2.35 122.54 2.39C122.31 2.86 122.24 3.39 122.24 3.9C122.24 4.21 122.27 4.53 122.35 4.82C122.51 5.49 122.88 5.99 123.5 5.99C124.02 5.99 124.36 5.63 124.54 5.12C124.76 5.63 125.13 5.99 125.68 5.99C126.54 5.99 126.79 4.94 126.78 3.94Z"/><path d="M130.25 6.09C130.25 5.63 130.22 5.17 130.02 4.75C129.76 4.2 129.29 4.11 129.05 4.11C128.7 4.11 128.28 4.26 128.05 4.79C127.86 5.19 127.83 5.63 127.83 6.09C127.83 6.52 127.86 7.04 128.09 7.48C128.34 7.94 128.76 8.06 129.04 8.06C129.35 8.06 129.79 7.94 130.04 7.39C130.22 6.99 130.25 6.55 130.25 6.09ZM129.77 6.02C129.77 6.45 129.77 6.84 129.71 7.21C129.63 7.76 129.3 7.93 129.04 7.93C128.82 7.93 128.48 7.79 128.37 7.23C128.31 6.89 128.31 6.36 128.31 6.02C128.31 5.66 128.31 5.28 128.36 4.97C128.47 4.28 128.9 4.23 129.04 4.23C129.23 4.23 129.61 4.34 129.72 4.9C129.77 5.23 129.77 5.66 129.77 6.02Z"/><path d="M124.45 15.94C124.46 15.58 124.45 15.17 124.37 14.85C124.32 14.63 124.23 14.45 124.08 14.35C124.01 14.3 123.95 14.27 123.87 14.27C123.78 14.27 123.68 14.32 123.62 14.4C123.56 14.48 123.55 14.58 123.57 14.67C123.59 14.75 123.64 14.81 123.71 14.87C123.96 15.05 124.13 15.3 124.2 15.59C124.23 15.69 124.24 15.8 124.24 15.9C124.24 16.64 123.96 17.4 123.31 17.4C122.85 17.4 122.5 17.08 122.32 16.66C122.37 16.43 122.39 16.18 122.38 15.94C122.38 15.86 122.38 15.79 122.37 15.72C122.33 15.6 122.27 15.51 122.15 15.51C122 15.51 121.97 15.71 121.97 15.9C121.97 16.15 122 16.4 122.05 16.63C121.89 17.08 121.58 17.4 121.13 17.4C120.63 17.4 120.31 16.99 120.18 16.47C120.14 16.31 120.12 16.12 120.11 15.94C120.11 15.44 120.29 14.99 120.5 14.55C120.51 14.52 120.52 14.48 120.51 14.44C120.5 14.39 120.46 14.35 120.41 14.33C120.38 14.31 120.36 14.31 120.33 14.31C120.28 14.31 120.23 14.34 120.2 14.39C119.98 14.85 119.91 15.38 119.91 15.9C119.91 16.21 119.94 16.53 120.01 16.81C120.18 17.48 120.55 17.99 121.17 17.99C121.69 17.99 122.02 17.63 122.2 17.12C122.42 17.63 122.8 17.99 123.35 17.99C124.2 17.99 124.46 16.93 124.45 15.94Z"/><path d="M128.3 19.92L128.3 19.74C127.9 19.74 127.85 19.7 127.85 19.42L127.85 15.94L127.03 16L127.03 16.18C127.43 16.18 127.48 16.22 127.48 16.5L127.48 17.74C127.31 17.53 127.06 17.38 126.75 17.38C126.07 17.38 125.47 17.95 125.47 18.69C125.47 19.42 126.03 19.98 126.69 19.98C127.06 19.98 127.31 19.79 127.46 19.61L127.46 19.98ZM127.46 19.24C127.46 19.35 127.46 19.36 127.4 19.46C127.22 19.73 126.96 19.86 126.72 19.86C126.46 19.86 126.25 19.71 126.12 19.49C125.97 19.26 125.95 18.93 125.95 18.69C125.95 18.48 125.96 18.14 126.13 17.88C126.25 17.7 126.47 17.51 126.78 17.51C126.98 17.51 127.22 17.6 127.4 17.86C127.46 17.95 127.46 17.96 127.46 18.07Z"/><path d="M137.95 11.81C137.95 11.28 137.65 10.98 137.53 10.86C137.2 10.54 136.81 10.46 136.39 10.38C135.83 10.27 135.16 10.14 135.16 9.56C135.16 9.21 135.42 8.8 136.28 8.8C137.38 8.8 137.43 9.7 137.45 10.01C137.46 10.1 137.57 10.1 137.57 10.1C137.7 10.1 137.7 10.05 137.7 9.86L137.7 8.85C137.7 8.68 137.7 8.61 137.59 8.61C137.54 8.61 137.52 8.61 137.39 8.73C137.36 8.77 137.26 8.86 137.22 8.89C136.84 8.61 136.43 8.61 136.28 8.61C135.06 8.61 134.68 9.28 134.68 9.84C134.68 10.19 134.84 10.47 135.11 10.69C135.43 10.95 135.71 11.01 136.43 11.15C136.65 11.19 137.47 11.35 137.47 12.07C137.47 12.58 137.12 12.98 136.34 12.98C135.5 12.98 135.14 12.41 134.95 11.56C134.92 11.43 134.91 11.39 134.81 11.39C134.68 11.39 134.68 11.46 134.68 11.64L134.68 12.96C134.68 13.13 134.68 13.2 134.79 13.2C134.84 13.2 134.85 13.19 135.04 13C135.06 12.98 135.06 12.96 135.24 12.77C135.68 13.19 136.13 13.2 136.34 13.2C137.49 13.2 137.95 12.53 137.95 11.81Z"/><path d="M140.76 13.09L140.76 12.78C140.1 12.78 140.06 12.73 140.06 12.34L140.06 8.67L138.66 8.78L138.66 9.09C139.31 9.09 139.4 9.15 139.4 9.64L139.4 12.33C139.4 12.78 139.29 12.78 138.62 12.78L138.62 13.09L139.72 13.06C140.07 13.06 140.42 13.08 140.76 13.09ZM140.21 7.05C140.21 6.78 139.98 6.52 139.68 6.52C139.34 6.52 139.14 6.8 139.14 7.05C139.14 7.32 139.37 7.58 139.67 7.58C140.01 7.58 140.21 7.3 140.21 7.05Z"/><path d="M146.42 13.09L146.42 12.78C145.9 12.78 145.65 12.78 145.64 12.48L145.64 10.57C145.64 9.71 145.64 9.4 145.33 9.04C145.19 8.87 144.86 8.67 144.28 8.67C143.55 8.67 143.08 9.1 142.8 9.72L142.8 8.67L141.39 8.78L141.39 9.09C142.09 9.09 142.17 9.16 142.17 9.65L142.17 12.33C142.17 12.78 142.06 12.78 141.39 12.78L141.39 13.09L142.52 13.06L143.64 13.09L143.64 12.78C142.97 12.78 142.86 12.78 142.86 12.33L142.86 10.49C142.86 9.45 143.57 8.89 144.21 8.89C144.84 8.89 144.95 9.43 144.95 10L144.95 12.33C144.95 12.78 144.84 12.78 144.17 12.78L144.17 13.09L145.3 13.06Z"/><path d="M149.95 15.47C149.95 15.44 149.93 15.41 149.91 15.39C148.87 14.61 148.18 12.61 148.18 11.01L148.18 10.17C148.18 8.57 148.87 6.57 149.91 5.79C149.93 5.77 149.95 5.74 149.95 5.71C149.95 5.66 149.9 5.61 149.85 5.61C149.83 5.61 149.81 5.62 149.79 5.63C148.69 6.46 147.64 8.46 147.64 10.17L147.64 11.01C147.64 12.72 148.69 14.72 149.79 15.55C149.81 15.56 149.83 15.57 149.85 15.57C149.9 15.57 149.95 15.52 149.95 15.47Z"/><path d="M156.48 10.7C156.49 10.27 156.48 9.77 156.38 9.37C156.32 9.11 156.21 8.89 156.03 8.76C155.95 8.7 155.87 8.67 155.78 8.67C155.66 8.67 155.54 8.73 155.47 8.83C155.4 8.93 155.38 9.04 155.41 9.15C155.43 9.25 155.49 9.33 155.58 9.4C155.88 9.62 156.09 9.93 156.18 10.28C156.21 10.4 156.23 10.53 156.23 10.65C156.23 11.56 155.88 12.48 155.09 12.48C154.53 12.48 154.1 12.1 153.88 11.58C153.94 11.3 153.97 11 153.96 10.7C153.96 10.61 153.96 10.52 153.94 10.44C153.9 10.29 153.82 10.18 153.68 10.18C153.49 10.18 153.46 10.43 153.46 10.65C153.46 10.96 153.49 11.26 153.56 11.55C153.36 12.09 152.98 12.48 152.43 12.48C151.82 12.48 151.43 11.98 151.28 11.35C151.23 11.15 151.2 10.92 151.19 10.7C151.19 10.1 151.41 9.54 151.66 9.01C151.68 8.97 151.69 8.92 151.68 8.88C151.66 8.82 151.61 8.77 151.55 8.74C151.52 8.72 151.49 8.72 151.46 8.72C151.4 8.72 151.34 8.75 151.3 8.81C151.03 9.38 150.94 10.02 150.94 10.65C150.94 11.03 150.98 11.42 151.07 11.77C151.27 12.58 151.72 13.2 152.48 13.2C153.11 13.2 153.52 12.76 153.74 12.14C154.01 12.76 154.47 13.2 155.14 13.2C156.18 13.2 156.49 11.91 156.48 10.7Z"/><path d="M161.18 15.56L161.18 15.35C160.69 15.35 160.63 15.3 160.63 14.95L160.63 10.7L159.62 10.78L159.62 11C160.11 11 160.17 11.05 160.17 11.39L160.17 12.9C159.97 12.65 159.66 12.47 159.29 12.47C158.46 12.47 157.73 13.15 157.73 14.06C157.73 14.95 158.41 15.64 159.21 15.64C159.66 15.64 159.97 15.4 160.15 15.18L160.15 15.64ZM160.15 14.74C160.15 14.86 160.15 14.88 160.07 15C159.86 15.33 159.55 15.49 159.24 15.49C158.93 15.49 158.68 15.3 158.51 15.04C158.33 14.75 158.31 14.35 158.31 14.06C158.31 13.81 158.32 13.39 158.52 13.07C158.67 12.85 158.94 12.62 159.31 12.62C159.56 12.62 159.85 12.73 160.07 13.04C160.15 13.16 160.15 13.18 160.15 13.3Z"/><path d="M164.7 11.85L164.7 11.28L164.45 11.28L164.45 11.83C164.45 12.57 164.15 12.95 163.78 12.95C163.11 12.95 163.11 12.04 163.11 11.87L163.11 9.09L164.54 9.09L164.54 8.78L163.11 8.78L163.11 6.94L162.86 6.94C162.85 7.76 162.55 8.83 161.57 8.87L161.57 9.09L162.42 9.09L162.42 11.85C162.42 13.08 163.35 13.2 163.71 13.2C164.42 13.2 164.7 12.49 164.7 11.85Z"/><path d="M168.15 11.01L168.15 10.17C168.15 8.46 167.1 6.46 166 5.63C165.98 5.62 165.96 5.61 165.94 5.61C165.89 5.61 165.84 5.66 165.84 5.71C165.84 5.74 165.86 5.77 165.88 5.79C166.92 6.57 167.61 8.57 167.61 10.17L167.61 11.01C167.61 12.61 166.92 14.61 165.88 15.39C165.86 15.41 165.84 15.44 165.84 15.47C165.84 15.52 165.89 15.57 165.94 15.57C165.96 15.57 165.98 15.56 166 15.55C167.1 14.72 168.15 12.72 168.15 11.01Z"/><path d="M170.8 15.59L170.8 5.59L169.58 5.59C169.47 5.59 169.38 5.68 169.38 5.79C169.38 5.9 169.47 5.99 169.58 5.99L170.4 5.99L170.4 15.19L169.58 15.19C169.47 15.19 169.38 15.28 169.38 15.39C169.38 15.5 169.47 15.59 169.58 15.59Z"/></svg><math class="td-math-a11y" xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi>p</mi><mtext>(</mtext><mi>t</mi><mtext>)</mtext><mtext> </mtext><mtext>=</mtext><mtext> </mtext><mn>1</mn><mtext> </mtext><mtext>-</mtext><mtext> </mtext><msup><mrow><mi>e</mi></mrow><mrow><mrow><mtext>-</mtext><mo>ζ</mo><mtext> </mtext><msub><mrow><mo>ω</mo></mrow><mrow><mn>0</mn></mrow></msub><mtext> </mtext><mi>t</mi></mrow></mrow></msup><mrow><mtext>[</mtext><mrow><mo>cos</mo><mtext>(</mtext><msub><mrow><mo>ω</mo></mrow><mrow><mi>d</mi></mrow></msub><mtext> </mtext><mi>t</mi><mtext>)</mtext><mtext> </mtext><mtext>+</mtext><mtext> </mtext><mfrac><mrow><mrow><mo>ζ</mo><mtext> </mtext><msub><mrow><mo>ω</mo></mrow><mrow><mn>0</mn></mrow></msub></mrow></mrow><mrow><msub><mrow><mo>ω</mo></mrow><mrow><mi>d</mi></mrow></msub></mrow></mfrac><mtext> </mtext><mo>sin</mo><mtext>(</mtext><msub><mrow><mo>ω</mo></mrow><mrow><mi>d</mi></mrow></msub><mtext> </mtext><mi>t</mi><mtext>)</mtext></mrow><mtext>]</mtext></mrow></mrow></math></div>
<p>which starts at 0, sweeps past 1, and settles back to 1. That overshoot past 1 is exactly why the spring overshoots its target and then settles.</p>
<h2>What the patent says</h2>
<p>US 11,042,388 B2, granted June 22, 2021, priority June 3, 2018. Inventors Jacob Xiao, Kyle Macomber, Joshua Shaffer, and John Harper, the same John Harper who created Core Animation in 2006.</p>
<p><img src="https://aleahim.com/images/blog/swiftui-is-one-graph/john-harper.png" alt="John Harper"></p>
<p><em>John Harper, via his GitHub.</em></p>
<p>Hold that name. Apple the company would not exist without Steve Jobs. <strong>The iPhone, and the whole fluid, animated, GPU-composited kingdom that grew on top of it, iOS, iPadOS, watchOS, tvOS, and visionOS, would not exist as we know it without John Harper.</strong> The same hand drew the engine that runs underneath all of it, from Core Animation in 2006 to the very graph this post is about. SwiftUI is just the newest room in a house whose foundation he poured. <strong>He is the John Carmack of Apple, its Linus Torvalds: the engineer whose work a billion people touch every day and whose name almost none of them know.</strong> That is a shame, and correcting it, in my own small way, is part of why I am writing all this.</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart LR
  I[&quot;Inputs, 0 to n&quot;] --&gt; F[&quot;Function&quot;]
  F --&gt; O[&quot;Cached output, persistent&quot;]
  O -.-&gt;|re-run| F
</pre>
</figure>
<p>As you can see in the image above, the patent lays the attribute graph out in plain words. It supports zero to n inputs, applies a function on the inputs to calculate an output, stores the output in a persistent memory structure, and whenever any input changes the function gets re-run. Affected attributes set a dirty bit, and the tree is traversed bottom up so that dirty attributes initiate an update. That is exactly what the behavior shows, down to the dirty bit and the bottom up pull, now in Apple’s own words.</p>
<p>It also spells out the animation record as the same four fields the behavior implies: from value, to value, animation function, start time.</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart LR
  T[&quot;Destination state, your data&quot;] --&gt; Cp[&quot;Copy&quot;]
  Cp --&gt; Inj[&quot;Intermediate value injected&quot;]
  Inj --&gt; Rn[&quot;Copy is rendered&quot;]
</pre>
</figure>
<p>And as the image above shows, the patent describes the method as generating a copy of the destination state and injecting an intermediate value into the copy for rendering. That is the model and presentation split you can watch the real framework perform.</p>
<p>I did not take any of this from the patent. The behavior and the patent are two independent witnesses, and they arrive at the same machine. When the framework you can observe and the patent Apple was granted describe the same structure, that structure is real, forced by the problem, not chosen by taste.</p>
<h2>One graph, one cone, drawn lazily</h2>
<p>That is the whole of it. A single demand-driven graph. State flows down through the environment, preferences flow up from children to parents, time is just another input, the graph recomputes only what truly changed, and it hands a coalesced layer tree to Core Animation to composite. Strip away the syntax and SwiftUI is one graph, one cone, drawn lazily.</p>
<p>And here is the part I will only hint at. This was never really about SwiftUI. It began with Core Animation, because I wanted to understand it, and <strong>the only way I trust to understand a thing is to build it again from nothing</strong>. But you cannot understand Core Animation without the drawing layer beneath it, so that came next.</p>
<p><img src="https://aleahim.com/images/blog/swiftui-is-one-graph/the-stack.jpg" alt="The engines beneath SwiftUI, the stack I have been rebuilding"></p>
<p>A text layer pulls you into typesetting. Transitions pull you into image processing. Each engine demanded the one below it, until the whole stack stood on its own and SwiftUI settled on top almost as an afterthought. None of it ships, and none of it is for sharing. It is mine, a way to learn the machine by rebuilding it, and it has a name: <a href="https://slayermotion.com">SlayerMotion</a>.</p>
<figure class="td-mermaid" data-td-mermaid>
<pre class="mermaid td-mermaid-source">flowchart TD
  SUI[&quot;SwiftUI, one graph&quot;] --&gt; CA[&quot;Core Animation, the compositor&quot;]
  CA --&gt; CG[&quot;Core Graphics, drawing&quot;]
  CA --&gt; CT[&quot;Core Text, typesetting&quot;]
  CA --&gt; CI[&quot;Core Image, effects&quot;]
</pre>
</figure>
<p><strong>Of the five, SwiftUI interests me the least, by a wide margin.</strong> It was not even born to be the future of the platform: it started as a way to make watchOS apps bearable to write, and only once it existed did Apple look at it and see what they had, and take it everywhere. It arrived with a quiet promise: that you could finally skip all of it, the dozen frameworks underneath, and just ship.</p>
<p><img src="https://aleahim.com/images/blog/swiftui-is-one-graph/the-shortcut.jpg" alt="What leaks through when you skip the frameworks"></p>
<p>That promise was a lie. You can ship, yes, but you have not learned the platform, you have learned a facade over it, and the day something leaks through, a layout that will not behave, an animation that stutters, text that measures wrong, you are standing on a stack you never met. The people who took SwiftUI as a way around the frameworks did not become Apple developers. They became SwiftUI users, and that is a different and smaller thing.</p>
<p>Set beside the engines underneath it, SwiftUI is genuinely uninteresting, boring even, a thin and tidy graph that does one clever thing and then gets out of the way. The one that floored me at the start still floors me most, and I suspect always will: Core Animation, a compositor that keeps an animation running smooth on its own clock while your app is busy elsewhere. The drawing layer, the type engine, the image pipeline are close behind. That is where the hard, strange, beautiful problems live, and that is the series. <strong>SwiftUI was just the easiest door into the story.</strong></p>]]></content:encoded>
</item>
<item>
<title>The Morlocks Built SwiftUI</title>
<link>https://aleahim.com/blog/morlocks-built-swiftui/</link>
<guid isPermaLink="true">https://aleahim.com/blog/morlocks-built-swiftui/</guid>
<pubDate>Thu, 28 May 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>The cynical read is that Apple kept the real tools and handed us toys. But the same engineer built Core Animation in 2007 and co-built SwiftUI in 2019, and that one fact says the opposite. On why the foundation never left, and the debt that comes due the day the abstraction breaks.</description>
<content:encoded><![CDATA[<h1>The Morlocks Built SwiftUI</h1>
<p>Swift is for the Eloi.</p>
<p>That is the cynical reading. There is a ladder here, and every rung hides more than the last:</p>
<ul><li><p><strong>C</strong>: too dangerous. Pointers, manual memory, undefined behavior.</p></li><li><p><strong>Objective-C</strong>: too dynamic. A runtime that will happily message a deallocated object and crash you in production.</p></li><li><p><strong>Swift</strong>: safe by default, but the pointers are still there if you go looking.</p></li><li><p><strong>Swift 6 strict concurrency</strong>: the compiler now walks you across every actor boundary so you never have to reason about a data race yourself.</p></li><li><p><strong>SwiftUI</strong>: declarative. Stop thinking about the render loop.</p></li><li><p><strong>SwiftData</strong>: persistence without ever learning what an object graph is.</p></li></ul>
<p>Most developers shipping apps today have never typed <code>CALayer</code>, because SwiftUI just works. Until it doesn’t.</p>
<p>It is tempting to call this condescension: the toolmakers kept the real tools and handed us the Fisher-Price version. It is a satisfying story. It is also wrong.</p>
<h2>The man who built both ends</h2>
<p>Core Animation was created by an Apple engineer named John Harper, and it is older than the device that made it famous. He built it under the codename “LayerKit”, and Apple was already showing it running on the Mac at WWDC 2006, months before the iPhone was announced. The foundational patent, US 8,130,226 (“Framework for Graphics Animation and Compositing Operations”), traces its priority to an application filed on August 4, 2006, and its own text still notes that “Core Animation” is just the “LayerKit” of that earlier filing. It reached the public in 2007: in the first iPhone OS, and later that year on the Mac in OS X 10.5 Leopard.</p>
<p>He left for Facebook in 2014. He came back to Apple and co-built SwiftUI: at WWDC 2019 he was on stage in “Building Custom Views with SwiftUI”, explaining how the view system actually works.</p>
<p>The person who built the rendering foundation that shipped in 2007 was, twelve years later, on the team building the declarative layer that sits on top of it. The same hands on both ends of the abstraction.</p>
<p>A Morlock in the daylight.</p>
<p>SwiftUI is not what happens when the serious engineers go build silicon and leave the toy framework to someone junior. It is what happens when the people who understand the foundation best decide what you should usually not have to think about. The implicit animation system, the idea that a state change should animate by default, that you declare what the UI is and let the framework diff and interpolate, is not a dumbing-down of Core Animation. It is Core Animation’s own philosophy, made the default instead of the opt-in.</p>
<h2>The foundations never left</h2>
<p>Of all of Apple’s low-level frameworks, almost everything named <code>Core</code> is written in C and meant to be called from anywhere: Core Graphics, Core Text, Core Audio, Core Foundation. Close to the metal, language-agnostic, no object model in the way.</p>
<p>Two are different. Core Animation and Core Data are written in Objective-C, object-model frameworks built around a tree of objects rather than a bag of C functions: Core Animation with its layer tree, Core Data with its managed-object graph. They were designed object-first because the problems they solve are object-shaped.</p>
<p>Those two still do not have Swift-native replacements. SwiftUI does not replace Core Animation. It sits on top of it. Your <code>.animation()</code> modifier drives a <code>CAAnimation</code>. Your view hierarchy resolves to a layer tree and a render server that has been doing this job, more or less unchanged, since 2007. SwiftData does the same thing to Core Data. The friendly declarative surface is new. The foundation underneath is the same machine it always was.</p>
<p>Core Animation did not need to change, because it was right the first time. The layer tree, the split between the model tree and the presentation tree, the separate render process, the implicit transactions: all still there, all still doing the work. What SwiftUI replaced was not Core Animation. It was UIKit’s interface to Core Animation: the manual animation blocks, the animator APIs, the layout system that had accreted cruft for a decade. The part that aged badly was how we talked to the machine, not the machine.</p>
<h2>So what is the truth we can’t handle?</h2>
<p>It is not that we are too stupid for pointers. Plenty of us could learn the layer tree in a weekend.</p>
<p>The truth is quieter: the foundation is still there, you have just stopped being able to see it, and that is a debt, not a gift. It comes due on the specific day SwiftUI does something you cannot explain. A frame that drops. An animation that fights itself. A view that will not redraw when every rule you know says it should. On that day the abstraction has failed, and the only people who can fix it are the ones who know what is underneath: the layer tree, implicit versus explicit animation, transforms, compositing, the render server.</p>
<p>Apple did not give us Swift and SwiftUI because we are too soft for the real thing. They gave them to us because the people who built the real thing learned, over fifteen years, which parts you genuinely should not have to touch most days. That is not contempt. It is the opposite. It is mastery deciding the default.</p>
<p>A good enough abstraction does not insult you. It just makes you comfortable on the surface, and helpless the day the machinery underneath asks whether you were paying attention. The layer tree is a weekend’s study. Learn it before the day you need it, because the framework will not tell you, in advance, which kind of day today is.</p>]]></content:encoded>
</item>
<item>
<title>Bringing Advanced SwiftUI Animations to macOS</title>
<link>https://aleahim.com/blog/swift-u-i-lab-advanced-animations/</link>
<guid isPermaLink="true">https://aleahim.com/blog/swift-u-i-lab-advanced-animations/</guid>
<pubDate>Sun, 13 Feb 2022 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>A port of SwiftUILab&apos;s Advanced Animations that also supports macOS</description>
<content:encoded><![CDATA[<p>When I first discovered <a href="https://swiftui-lab.com/swiftui-animations-part1/">SwiftUILab’s Advanced Animations</a>, I was impressed by the beautiful animations and transitions it demonstrated. However, I noticed that these examples were primarily focused on iOS, leaving macOS developers without a clear path to implement similar effects. This inspired me to create <a href="https://codeberg.org/Mihaela/SwiftUILab_AdvancedAnimations">SwiftUILab_AdvancedAnimations</a>, a port of these animations that works seamlessly on both iOS and macOS.</p>
<h2>The Challenge</h2>
<p>SwiftUI’s animation system is powerful but can behave differently across platforms. While iOS and macOS share the same SwiftUI framework, there are subtle differences in how animations are handled, especially when dealing with:</p>
<ul><li><p>Gesture recognizers</p></li><li><p>View transitions</p></li><li><p>Animation timing</p></li><li><p>Platform-specific UI elements</p></li></ul>
<p>My goal was to create a unified codebase that would work flawlessly on both platforms while maintaining the original animations’ elegance and performance.</p>
<h2>Project Structure</h2>
<p>I organized the project to make it easy to understand and extend:</p>
<pre><code>SwiftUILab_AA/
├── Examples/
│   ├── Animation1/
│   ├── Animation2/
│   └── ...
├── Shared/
│   ├── Views/
│   ├── Models/
│   └── Extensions/
└── App/
    ├── iOS/
    └── macOS/</code></pre>
<p>Each animation example has its own folder, making it easy to:</p>
<ul><li><p>Study individual animations in isolation</p></li><li><p>Copy and paste specific animations into other projects</p></li><li><p>Modify and experiment with different parameters</p></li></ul>
<h2>Key Features</h2>
<h3>1. Cross-Platform Compatibility</h3>
<p>The project uses SwiftUI’s platform-agnostic features while handling platform-specific requirements:</p>
<pre><code class="language-swift"><span class="tok-attribute">#if</span> <span class="tok-function">os</span>(i<span class="tok-type">OS</span>)
    <span class="tok-comment">// iOS-specific code</span>
<span class="tok-attribute">#elseif</span> <span class="tok-function">os</span>(mac<span class="tok-type">OS</span>)
    <span class="tok-comment">// macOS-specific code</span>
<span class="tok-attribute">#endif</span></code></pre>
<h3>2. Reusable Components</h3>
<p>I created a set of reusable components that work on both platforms:</p>
<pre><code class="language-swift"><span class="tok-keyword">struct</span> <span class="tok-type">AnimatedButton</span><span class="tok-operator">:</span> <span class="tok-type">View</span> {
    <span class="tok-attribute">@State</span> <span class="tok-keyword">private</span> <span class="tok-keyword">var</span> is<span class="tok-type">Pressed</span> <span class="tok-operator">=</span> <span class="tok-literal">false</span>

    <span class="tok-keyword">var</span> body<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">View</span> {
        <span class="tok-type">Button</span>(action<span class="tok-operator">:</span> {}) {
            <span class="tok-type">Text</span>(<span class="tok-string">"Animate"</span>)
                <span class="tok-operator">.</span><span class="tok-function">scaleEffect</span>(is<span class="tok-type">Pressed</span> <span class="tok-operator">?</span> <span class="tok-number">0.95</span> <span class="tok-operator">:</span> <span class="tok-number">1.0</span>)
                <span class="tok-operator">.</span><span class="tok-function">animation</span>(<span class="tok-operator">.</span><span class="tok-function">spring</span>(), value<span class="tok-operator">:</span> is<span class="tok-type">Pressed</span>)
        }
        <span class="tok-operator">.</span><span class="tok-function">buttonStyle</span>(<span class="tok-type">PlainButtonStyle</span>())
        <span class="tok-operator">.</span>on<span class="tok-type">Hover</span> { hovering <span class="tok-keyword">in</span>
            is<span class="tok-type">Pressed</span> <span class="tok-operator">=</span> hovering
        }
    }
}</code></pre>
<h3>3. Gesture Handling</h3>
<p>The project includes platform-appropriate gesture handling:</p>
<pre><code class="language-swift"><span class="tok-keyword">struct</span> <span class="tok-type">DragGestureView</span><span class="tok-operator">:</span> <span class="tok-type">View</span> {
    <span class="tok-attribute">@State</span> <span class="tok-keyword">private</span> <span class="tok-keyword">var</span> offset <span class="tok-operator">=</span> <span class="tok-type">CGSize</span><span class="tok-operator">.</span>zero

    <span class="tok-keyword">var</span> body<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">View</span> {
        <span class="tok-type">Rectangle</span>()
            <span class="tok-operator">.</span><span class="tok-function">fill</span>(<span class="tok-type">Color</span><span class="tok-operator">.</span>blue)
            <span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">100</span>, height<span class="tok-operator">:</span> <span class="tok-number">100</span>)
            <span class="tok-operator">.</span><span class="tok-function">offset</span>(offset)
            <span class="tok-operator">.</span><span class="tok-function">gesture</span>(
                <span class="tok-type">DragGesture</span>()
                    <span class="tok-operator">.</span>on<span class="tok-type">Changed</span> { value <span class="tok-keyword">in</span>
                        offset <span class="tok-operator">=</span> value<span class="tok-operator">.</span>translation
                    }
                    <span class="tok-operator">.</span>on<span class="tok-type">Ended</span> { _ <span class="tok-keyword">in</span>
                        <span class="tok-function">withAnimation</span>(<span class="tok-operator">.</span><span class="tok-function">spring</span>()) {
                            offset <span class="tok-operator">=</span> <span class="tok-operator">.</span>zero
                        }
                    }
            )
    }
}</code></pre>
<h2>Example Animations</h2>
<h3>1. Morphing Shapes</h3>
<p>One of the most impressive animations is the shape morphing effect:</p>
<pre><code class="language-swift"><span class="tok-keyword">struct</span> <span class="tok-type">MorphingShape</span><span class="tok-operator">:</span> <span class="tok-type">View</span> {
    <span class="tok-attribute">@State</span> <span class="tok-keyword">private</span> <span class="tok-keyword">var</span> is<span class="tok-type">Morphed</span> <span class="tok-operator">=</span> <span class="tok-literal">false</span>

    <span class="tok-keyword">var</span> body<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">View</span> {
        <span class="tok-type">Circle</span>()
            <span class="tok-operator">.</span><span class="tok-function">fill</span>(<span class="tok-type">Color</span><span class="tok-operator">.</span>blue)
            <span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">100</span>, height<span class="tok-operator">:</span> <span class="tok-number">100</span>)
            <span class="tok-operator">.</span><span class="tok-function">scaleEffect</span>(is<span class="tok-type">Morphed</span> <span class="tok-operator">?</span> <span class="tok-number">1.5</span> <span class="tok-operator">:</span> <span class="tok-number">1.0</span>)
            <span class="tok-operator">.</span><span class="tok-function">animation</span>(<span class="tok-operator">.</span><span class="tok-function">spring</span>(response<span class="tok-operator">:</span> <span class="tok-number">0.6</span>, damping<span class="tok-type">Fraction</span><span class="tok-operator">:</span> <span class="tok-number">0.6</span>), value<span class="tok-operator">:</span> is<span class="tok-type">Morphed</span>)
            <span class="tok-operator">.</span>on<span class="tok-type">TapGesture</span> {
                is<span class="tok-type">Morphed</span><span class="tok-operator">.</span><span class="tok-function">toggle</span>()
            }
    }
}</code></pre>
<h3>2. Custom Transitions</h3>
<p>The project includes several custom transitions that work on both platforms:</p>
<pre><code class="language-swift"><span class="tok-keyword">extension</span> <span class="tok-type">AnyTransition</span> {
    <span class="tok-keyword">static</span> <span class="tok-keyword">var</span> custom<span class="tok-type">Scale</span><span class="tok-operator">:</span> <span class="tok-type">AnyTransition</span> {
        <span class="tok-operator">.</span><span class="tok-function">scale</span>(scale<span class="tok-operator">:</span> <span class="tok-number">0.1</span>)
        <span class="tok-operator">.</span><span class="tok-function">combined</span>(with<span class="tok-operator">:</span> <span class="tok-operator">.</span>opacity)
    }
}</code></pre>
<h2>Implementation Details</h2>
<h3>1. View Extensions</h3>
<p>I created several extensions to make animations more reusable:</p>
<pre><code class="language-swift"><span class="tok-keyword">extension</span> <span class="tok-type">View</span> {
    <span class="tok-keyword">func</span> <span class="tok-function">animateOnHover</span>() <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-keyword">some</span> <span class="tok-type">View</span> {
        <span class="tok-keyword">self</span><span class="tok-operator">.</span><span class="tok-function">modifier</span>(<span class="tok-type">HoverAnimationModifier</span>())
    }
}</code></pre>
<h3>2. Animation Timing</h3>
<p>Careful attention was paid to animation timing to ensure smooth performance:</p>
<pre><code class="language-swift"><span class="tok-keyword">struct</span> <span class="tok-type">TimingAnimation</span><span class="tok-operator">:</span> <span class="tok-type">View</span> {
    <span class="tok-attribute">@State</span> <span class="tok-keyword">private</span> <span class="tok-keyword">var</span> is<span class="tok-type">Animating</span> <span class="tok-operator">=</span> <span class="tok-literal">false</span>

    <span class="tok-keyword">var</span> body<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">View</span> {
        <span class="tok-type">Circle</span>()
            <span class="tok-operator">.</span><span class="tok-function">fill</span>(<span class="tok-type">Color</span><span class="tok-operator">.</span>red)
            <span class="tok-operator">.</span><span class="tok-function">frame</span>(width<span class="tok-operator">:</span> <span class="tok-number">50</span>, height<span class="tok-operator">:</span> <span class="tok-number">50</span>)
            <span class="tok-operator">.</span><span class="tok-function">offset</span>(y<span class="tok-operator">:</span> is<span class="tok-type">Animating</span> <span class="tok-operator">?</span> <span class="tok-number">-100</span> <span class="tok-operator">:</span> <span class="tok-number">0</span>)
            <span class="tok-operator">.</span><span class="tok-function">animation</span>(
                <span class="tok-operator">.</span><span class="tok-function">timingCurve</span>(<span class="tok-number">0.68</span>, <span class="tok-number">-0.6</span>, <span class="tok-number">0.32</span>, <span class="tok-number">1.6</span>, duration<span class="tok-operator">:</span> <span class="tok-number">1</span>),
                value<span class="tok-operator">:</span> is<span class="tok-type">Animating</span>
            )
            <span class="tok-operator">.</span>on<span class="tok-type">Appear</span> {
                is<span class="tok-type">Animating</span> <span class="tok-operator">=</span> <span class="tok-literal">true</span>
            }
    }
}</code></pre>
<h2>Benefits for Developers</h2>
<ol><li><p><strong>Cross-Platform Learning</strong>: Developers can learn SwiftUI animations that work on both iOS and macOS</p></li><li><p><strong>Ready-to-Use Examples</strong>: Each animation is self-contained and can be easily copied into other projects</p></li><li><p><strong>Performance Optimized</strong>: Animations are optimized for smooth performance on both platforms</p></li><li><p><strong>Educational Resource</strong>: The project serves as a comprehensive guide to SwiftUI animations</p></li></ol>
<h2>Future Improvements</h2>
<p>The project is actively maintained with several planned enhancements:</p>
<ol><li><p>Adding more complex animation examples</p></li><li><p>Implementing accessibility features</p></li><li><p>Creating a documentation site with interactive examples</p></li><li><p>Adding support for visionOS</p></li></ol>
<h2>Conclusion</h2>
<p>SwiftUILab_AdvancedAnimations bridges the gap between iOS and macOS animation development in SwiftUI. By providing a unified codebase and clear examples, it helps developers create beautiful, performant animations that work across Apple’s platforms.</p>
<p>Whether you’re building for iOS, macOS, or both, this project provides valuable insights into SwiftUI’s animation capabilities and best practices for cross-platform development.</p>
<h2>Resources</h2>
<ul><li><a href="https://codeberg.org/Mihaela/SwiftUILab_AdvancedAnimations">Codeberg Repository</a></li><li><a href="https://swiftui-lab.com/swiftui-animations-part1/">Original SwiftUILab Article</a></li><li><a href="https://developer.apple.com/documentation/swiftui">SwiftUI Documentation</a></li></ul>]]></content:encoded>
</item>
<item>
<title>Core Animation Layers forming a 3D cube</title>
<link>https://aleahim.com/blog/core-animation-3d-cube/</link>
<guid isPermaLink="true">https://aleahim.com/blog/core-animation-3d-cube/</guid>
<pubDate>Sat, 06 Mar 2021 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>Core Animation in 2.5D</description>
<content:encoded><![CDATA[<p>I’ve been researching <code>Core Animation</code> framework for the past few months.
I’ve started with several books on the subject, but I found watching related WWDC videos most rewarding. The presenters put the content in a relevant context which  makes it easier to apprehend and learn from it.</p>
<h2>1. Introduction</h2>
<p>One WWDC session particularly intrigued me: “2011–421 Core Animation Essentials”. They presented their demo named: “Layers in Perspective”, and it showed six layers, forming a flattened cube:
<img src="https://aleahim.com/images/cacube/02_cube_5sides.png" alt="Five coloured numbered squares laid out as a cross on a grey background: 5 in the centre, 4 above, 3 below, 1 on the left and 2 on the right."></p>
<p>The sixth layer is hiding behind the layer number 5. It has a lower <code>zPosition</code> then the layer above it.</p>
<p><img src="https://aleahim.com/images/cacube/03_cube_6sides.png" alt="An iPad screenshot of six coloured, numbered panels floating at different angles in a diagonal tangle, with switches at the bottom: Box off, Open off, Show Z on."></p>
<p>They have also demonstrated opening and closing the cube formation.</p>
<p><img src="https://aleahim.com/images/cacube/04_cube_filmstrip.png" alt="Eight iPad frames in a row showing the cross of numbered coloured panels folding step by step into a cube; the seventh frame shows faces 4, 5 and 2, the last only 4 and 5."></p>
<p>So, I have decided to demonstrate that.</p>
<p>Here’s a link to a Codeberg repo with the source code:
<a href="https://codeberg.org/Mihaela/CubeIn3DWithCoreAnimation">Core Animation 3D Cube</a></p>
<p>Here’s the animation:</p>
<p><img src="https://aleahim.com/images/cacube/05_CoreAnimation_3D_Cube.gif" alt="An animation on a phone screen of rounded numbered tiles on a black background, here in its first frame: 5 grey above, 1 blue, 4 purple and 3 green in a row, 6 yellow below, tilted slightly."></p>
<p>You can also see it on <a href="https://www.youtube.com/watch?v=exIGbi36_bk">You Tube</a></p>
<p>Layers in <code>Core Animation</code> live in <code>3D</code> geometry. But a layer is a <code>2D</code> construct, so <code>Core Animation</code> coordinate space is called a <code>2.5D</code> geometry.</p>
<p>To illustrate that just see what happens when you mess up your transformations.</p>
<p><img src="https://aleahim.com/images/cacube/06_Intersecting_Layers.png" alt="Coloured layers cutting through one another: a red ring with a white swirl, crossed by a blue panel, a purple disc and a yellow panel, on a black background, showing layers that intersect."></p>
<p>Layers are <code>2D</code> objects, they don’t understand the third dimension.
They are like playing cards in space., and there is no <code>depth buffer</code> available.</p>
<p>And also, intersecting layers should be avoided because in the image above, Core Animation needs to do a lot of work.
So just to draw the <code>red</code> layer intersecting only the <code>blue</code> layer, Core Animation needs to</p>
<ul><li><p>cut the <code>red</code> layer into two pieces</p></li><li><p>render back part of the <code>red</code> layer</p></li><li><p>then render the full <code>blue</code> layer</p></li><li><p>then render the front part of the <code>red</code> layer again
And all that work is for just intersection, and here we have multiple.</p></li></ul>
<h2>2. Building the Cube in 3D</h2>
<h3>2.1. Setting up the multi-platform project</h3>
<p>I wanted the project to fun on the <code>macOS</code> , <code>iOS</code> and <code>iPadOS</code>, so I used <a href="https://codeberg.org/Mihaela/allapples">AllApples</a> Swift package.</p>
<p>After removing the storyboards and pimping up the <code>AppDelegate</code> and <code>main.swift</code> for the <code>macOS</code> version, and <code>SceneDelegate</code> for the mobile versions, I was ready to start.</p>
<h4>2.1.1. <code>main.swift</code> for the macOS</h4>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">Cocoa</span>
<span class="tok-keyword">let</span> delegate <span class="tok-operator">=</span> <span class="tok-type">AppDelegate</span>()
<span class="tok-type">NSApplication</span><span class="tok-operator">.</span>shared<span class="tok-operator">.</span>delegate <span class="tok-operator">=</span> delegate
_ <span class="tok-operator">=</span> <span class="tok-type">NSApplicationMain</span>(<span class="tok-type">CommandLine</span><span class="tok-operator">.</span>argc, <span class="tok-type">CommandLine</span><span class="tok-operator">.</span>unsafe<span class="tok-type">Argv</span>)</code></pre>
<h4>2.1.2. AppDelegate for the <code>macOS</code></h4>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">Cocoa</span>
<span class="tok-keyword">import</span> <span class="tok-type">AllApples</span>

<span class="tok-keyword">class</span> <span class="tok-type">AppDelegate</span><span class="tok-operator">:</span> <span class="tok-type">NSObject</span>, <span class="tok-type">NSApplicationDelegate</span> {
  <span class="tok-keyword">private</span> <span class="tok-keyword">var</span> window<span class="tok-operator">:</span> <span class="tok-type">NSWindow</span><span class="tok-operator">?</span>
  <span class="tok-keyword">func</span> <span class="tok-function">applicationDidFinishLaunching</span>(_ a<span class="tok-type">Notification</span><span class="tok-operator">:</span> <span class="tok-type">Notification</span>) {
    window <span class="tok-operator">=</span> <span class="tok-type">AppSceneDelegate</span><span class="tok-operator">.</span><span class="tok-function">makeWindow_Mac</span>(the<span class="tok-type">VC</span><span class="tok-operator">:</span> <span class="tok-type">CommonViewController</span>())
  }
}</code></pre>
<h4>2.1.3. SceneDelegate for the <code>iOS</code> and <code>iPadOS</code></h4>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">UIKit</span>
<span class="tok-keyword">import</span> <span class="tok-type">AllApples</span>

<span class="tok-keyword">class</span> <span class="tok-type">SceneDelegate</span><span class="tok-operator">:</span> <span class="tok-type">UIResponder</span>, <span class="tok-type">UIWindowSceneDelegate</span> {
  <span class="tok-keyword">var</span> window<span class="tok-operator">:</span> <span class="tok-type">UIWindow</span><span class="tok-operator">?</span>
  <span class="tok-keyword">func</span> <span class="tok-function">scene</span>(_ scene<span class="tok-operator">:</span> <span class="tok-type">UIScene</span>, will<span class="tok-type">ConnectTo</span> session<span class="tok-operator">:</span> <span class="tok-type">UISceneSession</span>, options connection<span class="tok-type">Options</span><span class="tok-operator">:</span> <span class="tok-type">UIScene</span><span class="tok-operator">.</span><span class="tok-type">ConnectionOptions</span>) {
    <span class="tok-keyword">guard</span> <span class="tok-keyword">let</span> a<span class="tok-type">Scene</span> <span class="tok-operator">=</span> (scene <span class="tok-keyword">as</span><span class="tok-operator">?</span> <span class="tok-type">UIWindowScene</span>) <span class="tok-keyword">else</span> { <span class="tok-keyword">return</span> }
    window <span class="tok-operator">=</span> <span class="tok-type">AppSceneDelegate</span><span class="tok-operator">.</span><span class="tok-function">makeWindow_iOS</span>(the<span class="tok-type">Scene</span><span class="tok-operator">:</span> a<span class="tok-type">Scene</span>, the<span class="tok-type">VC</span><span class="tok-operator">:</span> <span class="tok-type">CommonViewController</span>())
  }
}</code></pre>
<h3>2.2. Building the Basic Blocks</h3>
<p>The first I did is make a <code>PlainLayerView </code>.
It is an <code>AView</code> descendant, which means that it is <code>typedef-ed</code> to be either a <code>UIView</code> or a <code>NSView</code>.</p>
<p>It is an intermediary object just to set up a thing on the <code>macOS</code> as well (doesn’t work yet).</p>
<p>I then created <code>CustomLayerView</code> to have nice sides for the cube, with <code>CATextLayer</code> as the number of the cube side, and a nice rounded border, so that we can peek into our cube while rotating.</p>
<p>Here’s the image of all six layers drawn by using a <code>CustomLayerView</code></p>
<p><img src="https://aleahim.com/images/cacube/07_original_abandoned_cube_layout.png" alt="The original, abandoned layout of the cube’s faces: rounded numbered tiles in a cross on black, 2 red in the centre with 1 blue on its left, 3 green and 4 purple on its right, 5 grey above and 6 yellow below."></p>
<p>This layout was abandoned because I couldn’t make the transformation of <code>purple</code> view to work when transforming in <code>3D</code>.</p>
<p><img src="https://aleahim.com/images/cacube/08_side4_broken.png" alt="A half-folded cube where side 4, the purple tile, stays flat and detached beside the blue 1, green 3, grey top and yellow bottom faces, which are folded and mirrored."></p>
<p>The solution is to add an additional <code>CATransformLayer</code> to the <code>green</code> layer, and mount the <code>purple</code> layer onto it. As explained in this blog post by Oliver Drobnik <a href="https://www.cocoanetics.com/2012/08/cubed-coreanimation-conundrum/"> Cubed CoreAnimation Conundrum.</a></p>
<p>But I didn’t want to lose the linearity of the solution, and I used the approach demonstrated in the mentioned WWDC session: “2011–421 Core Animation Essentials”</p>
<p>They used the <code>zOrder</code> property of a layer, and so I put <code>purple</code> layer on top of the <code>red</code> layer to achieve that.</p>
<pre><code class="language-swift">    <span class="tok-keyword">if</span> number <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-number">4</span> {
      view<span class="tok-operator">.</span>layer<span class="tok-operator">.</span>z<span class="tok-type">Position</span> <span class="tok-operator">=</span> <span class="tok-number">1</span>
    }</code></pre>
<p>As you can see in the image below, the <code>purple</code> layer is in front of the <code>red</code> layer, which is obvious when we rotate the flattened cube.</p>
<p><img src="https://aleahim.com/images/cacube/09_layers_zPosition.png" alt="Two views of the numbered tiles: on the left the cross with 4 purple in the centre; on the right the same tiles rotated in space, drawn mirrored and in a different order."></p>
<h3>2.3. Turning the Transform On and Off</h3>
<p>I did take the approach that Over Drobnik did in his article: <a href="https://www.cocoanetics.com/2012/08/cubed-coreanimation-conundrum/"> Cubed CoreAnimation Conundrum </a>, and used it like this:</p>
<pre><code class="language-swift">	side<span class="tok-number">4.</span>layer<span class="tok-operator">?</span><span class="tok-operator">.</span>z<span class="tok-type">Position</span> <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span> <span class="tok-operator">:</span> <span class="tok-number">1</span>
    side<span class="tok-number">1.</span>layer<span class="tok-operator">?</span><span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">1</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>)  <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
    side<span class="tok-number">2.</span>layer<span class="tok-operator">?</span><span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">2</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>)  <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
    side<span class="tok-number">3.</span>layer<span class="tok-operator">?</span><span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">3</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>)  <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
    side<span class="tok-number">4.</span>layer<span class="tok-operator">?</span><span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">4</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>)  <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
    side<span class="tok-number">5.</span>layer<span class="tok-operator">?</span><span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">5</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>)  <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
    side<span class="tok-number">6.</span>layer<span class="tok-operator">?</span><span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">6</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>)  <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span></code></pre>
<h3>2.4. Transforming the Layers to Form a Cube</h3>
<p>I didn’t use his transform code, since he used that additional <code>CATransformLayer</code>, so it wouldn’t work. So, here’s a small extension on the <code>CATransform3D</code></p>
<pre><code class="language-swift"><span class="tok-keyword">public</span> <span class="tok-keyword">extension</span> <span class="tok-type">CATransform3D</span> {
  <span class="tok-keyword">static</span> <span class="tok-keyword">func</span> <span class="tok-function">transformFor3DCubeSide</span>(_ number<span class="tok-operator">:</span> <span class="tok-type">Int</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">CATransform3D</span> {

    <span class="tok-keyword">let</span> half<span class="tok-type">Pi</span> <span class="tok-operator">=</span> <span class="tok-type">CGFloat</span>(<span class="tok-type">Double</span><span class="tok-operator">.</span>pi) <span class="tok-operator">/</span> <span class="tok-number">2.0</span>
    <span class="tok-keyword">var</span> trans <span class="tok-operator">=</span> <span class="tok-type">CATransform3DIdentity</span>
    <span class="tok-keyword">switch</span> number {
      <span class="tok-keyword">case</span> <span class="tok-number">1</span><span class="tok-operator">:</span>
        trans <span class="tok-operator">=</span> <span class="tok-type">CATransform3DMakeRotation</span>(half<span class="tok-type">Pi</span>, <span class="tok-number">0</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">case</span> <span class="tok-number">2</span><span class="tok-operator">:</span>
        trans <span class="tok-operator">=</span> <span class="tok-type">CATransform3DIdentity</span>
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">case</span> <span class="tok-number">3</span><span class="tok-operator">:</span>
        trans <span class="tok-operator">=</span> <span class="tok-type">CATransform3DMakeRotation</span>(<span class="tok-operator">-</span>half<span class="tok-type">Pi</span>, <span class="tok-number">0</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">case</span> <span class="tok-number">4</span><span class="tok-operator">:</span>
        trans <span class="tok-operator">=</span> <span class="tok-type">CATransform3DMakeTranslation</span>(<span class="tok-number">0</span>, <span class="tok-number">0</span>, z<span class="tok-type">Width</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">case</span> <span class="tok-number">5</span><span class="tok-operator">:</span>
        trans <span class="tok-operator">=</span> <span class="tok-type">CATransform3DMakeRotation</span>(<span class="tok-operator">-</span>half<span class="tok-type">Pi</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>, <span class="tok-number">0</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">case</span> <span class="tok-number">6</span><span class="tok-operator">:</span>
        trans <span class="tok-operator">=</span> <span class="tok-type">CATransform3DMakeRotation</span>(half<span class="tok-type">Pi</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>, <span class="tok-number">0</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">default</span><span class="tok-operator">:</span>
        <span class="tok-keyword">break</span>
    }
    <span class="tok-keyword">return</span> trans
  }
}</code></pre>
<p>I actually used the approach form that WWDC session, and also used <code>anchorPoint</code> properties of the <code>CALayer</code>.</p>
<h3>2.5. Positioning Cube Sides</h3>
<p>Here’s a little extension on <code>CGPoint</code> that returns a tuple of our cube side positions and anchor points:</p>
<pre><code class="language-swift"><span class="tok-keyword">public</span> <span class="tok-keyword">extension</span> <span class="tok-type">CGPoint</span> {
  <span class="tok-keyword">static</span> <span class="tok-keyword">func</span> <span class="tok-function">anchorPointAndPositionForCubeSideLayer</span>(number<span class="tok-operator">:</span> <span class="tok-type">Int</span>, side<span class="tok-type">Size</span><span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> (anchor<span class="tok-type">Point</span><span class="tok-operator">:</span> <span class="tok-type">CGPoint</span>, position<span class="tok-operator">:</span> <span class="tok-type">CGPoint</span>) {
    <span class="tok-keyword">var</span> result<span class="tok-type">AnchorPoint</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.5</span>, y<span class="tok-operator">:</span><span class="tok-number">0.5</span>)
    <span class="tok-keyword">var</span> result<span class="tok-type">Position</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.0</span>, y<span class="tok-operator">:</span><span class="tok-number">0.0</span>)
    <span class="tok-keyword">let</span> half<span class="tok-type">SideSize</span><span class="tok-operator">:</span> <span class="tok-type">CGFloat</span> <span class="tok-operator">=</span> side<span class="tok-type">Size</span> <span class="tok-operator">/</span> <span class="tok-number">2.0</span>
    <span class="tok-keyword">switch</span> number {
      <span class="tok-keyword">case</span> <span class="tok-number">1</span><span class="tok-operator">:</span>
        result<span class="tok-type">AnchorPoint</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">1.0</span>, y<span class="tok-operator">:</span><span class="tok-number">0.5</span>)
        result<span class="tok-type">Position</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-operator">-</span>half<span class="tok-type">SideSize</span>, y<span class="tok-operator">:</span><span class="tok-number">0.0</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">case</span> <span class="tok-number">2</span><span class="tok-operator">:</span>
        result<span class="tok-type">AnchorPoint</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.5</span>, y<span class="tok-operator">:</span><span class="tok-number">0.5</span>)
        result<span class="tok-type">Position</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.0</span>, y<span class="tok-operator">:</span><span class="tok-number">0.0</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">case</span> <span class="tok-number">3</span><span class="tok-operator">:</span>
        result<span class="tok-type">AnchorPoint</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.0</span>, y<span class="tok-operator">:</span><span class="tok-number">0.5</span>)
        result<span class="tok-type">Position</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span>half<span class="tok-type">SideSize</span>, y<span class="tok-operator">:</span><span class="tok-number">0.0</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">case</span> <span class="tok-number">4</span><span class="tok-operator">:</span>
        result<span class="tok-type">AnchorPoint</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.5</span>, y<span class="tok-operator">:</span><span class="tok-number">0.5</span>)
        result<span class="tok-type">Position</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.0</span>, y<span class="tok-operator">:</span><span class="tok-number">0.0</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">case</span> <span class="tok-number">5</span><span class="tok-operator">:</span>
        result<span class="tok-type">AnchorPoint</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.5</span>, y<span class="tok-operator">:</span><span class="tok-number">1.0</span>)
        result<span class="tok-type">Position</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.0</span>, y<span class="tok-operator">:</span><span class="tok-operator">-</span>half<span class="tok-type">SideSize</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">case</span> <span class="tok-number">6</span><span class="tok-operator">:</span>
        result<span class="tok-type">AnchorPoint</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.5</span>, y<span class="tok-operator">:</span><span class="tok-number">0.0</span>)
        result<span class="tok-type">Position</span> <span class="tok-operator">=</span> <span class="tok-type">CGPoint</span>(x<span class="tok-operator">:</span><span class="tok-number">0.0</span>, y<span class="tok-operator">:</span>half<span class="tok-type">SideSize</span>)
        <span class="tok-keyword">break</span>
      <span class="tok-keyword">default</span><span class="tok-operator">:</span>
        <span class="tok-keyword">break</span>
    }
    <span class="tok-keyword">return</span> (anchor<span class="tok-type">Point</span><span class="tok-operator">:</span> result<span class="tok-type">AnchorPoint</span>, position<span class="tok-operator">:</span> result<span class="tok-type">Position</span>)
  }
}</code></pre>
<p>In the image below I have marked where the <code>anchor points</code> are for each layer:</p>
<p><img src="https://aleahim.com/images/cacube/10_anchor_points.png" alt="The cross of numbered tiles, 2 red in the centre, with a black cross marking the anchor point of each tile: one at the centre of 2, one at the centre of 4 above and right, and one on each edge shared with 1, 3, 5 and 6."></p>
<p>The only fallacy in the image above, is that the <code>purple</code> layer is actually above our <code>red layer</code>, but I wanted to show where those anchor points are.
So, the actual image looks like this, but we now don’t see the <code>red</code> layer.
<img src="https://aleahim.com/images/cacube/11_anchor_points.png" alt="The same cross with 4 purple in the centre, and black crosses marking the anchor points at the tiles’ shared edges and at the centre of 4."></p>
<p>An Anchor point is a center of rotation. It determines how will the layer rotate.
Imagine holding a playing card with two fingers. Then try to spin the card. The anchor point of that card is where you are holding it with fingers.</p>
<h2>3. Responding to Gestures</h2>
<p>I made a small <code>GestureRecognizerView</code> to be able to respond to gestures and move, rotate and scale our layers.</p>
<p>It hooks-up:</p>
<ul><li><p><code>NSPanGestureRecognizer</code> and <code>UIPanGestureRecognizer</code></p></li><li><p><code>func rotate(with event: NSEvent)</code> and <code>UIRotationGestureRecognizer</code></p></li><li><p><code>NSClickGestureRecognizer</code> and <code>UITapGestureRecognizer</code></p></li><li><p><code>func magnify(with event: NSEvent)</code> and <code>UIPinchGestureRecognizer</code></p></li></ul>
<p>It then exposes all those events to the developer to use:</p>
<pre><code class="language-swift"><span class="tok-keyword">public</span> <span class="tok-keyword">extension</span> <span class="tok-type">GestureRecognizerView</span> {
  <span class="tok-attribute">@objc</span> <span class="tok-keyword">func</span> <span class="tok-function">rotationChanged</span>(degrees<span class="tok-operator">:</span> <span class="tok-type">Float</span>) {}
  <span class="tok-attribute">@objc</span> <span class="tok-keyword">func</span> <span class="tok-function">rotationChanged</span>(radians<span class="tok-operator">:</span> <span class="tok-type">Float</span>) {}
  <span class="tok-attribute">@objc</span> <span class="tok-keyword">func</span> <span class="tok-function">displacementChanged</span>(displacement<span class="tok-operator">:</span> <span class="tok-type">CGPoint</span>) {}
  <span class="tok-attribute">@objc</span> <span class="tok-keyword">func</span> <span class="tok-function">scaleChanged</span>(scale<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>) {}
  <span class="tok-attribute">@objc</span> <span class="tok-keyword">func</span> <span class="tok-function">tapHappened</span>() {}
}</code></pre>
<h2>4. Building a Layer to hold a Cube</h2>
<p><code>CACube3DView</code> will hold the six layers than (can) make a cube.
In order for <code>Core Animation</code> to render the transformed views in perspective, there is a property <code>sublayerTransform</code>.</p>
<p>You either use that property of your parent layer, or add another layer class to your layer hierarchy: <code>CATransformLayer</code>. I opted to use that.</p>
<pre><code class="language-swift"><span class="tok-keyword">private</span>(set) <span class="tok-keyword">public</span> <span class="tok-keyword">lazy</span> <span class="tok-keyword">var</span> transformed<span class="tok-type">Layer</span><span class="tok-operator">:</span> <span class="tok-type">CALayer</span> <span class="tok-operator">=</span> {
    <span class="tok-keyword">let</span> l <span class="tok-operator">=</span> <span class="tok-type">CATransformLayer</span>()
    l<span class="tok-operator">.</span>name <span class="tok-operator">=</span> <span class="tok-string">"Transform Layer"</span>
    <span class="tok-attribute">#if</span> <span class="tok-function">os</span>(<span class="tok-type">OSX</span>)
    l<span class="tok-operator">.</span>is<span class="tok-type">GeometryFlipped</span> <span class="tok-operator">=</span> <span class="tok-literal">true</span>
    <span class="tok-attribute">#endif</span>
    <span class="tok-keyword">return</span> l
}()</code></pre>
<p>When adding sublayers, I add them to this <code>transformedLayer</code> property, and not my view’s layer.</p>
<pre><code class="language-swift"><span class="tok-keyword">func</span> <span class="tok-function">addSideSubview</span>(_ subview<span class="tok-operator">:</span> <span class="tok-type">AView</span>) {
    <span class="tok-function">addSubview</span>(subview)

    <span class="tok-attribute">#if</span> <span class="tok-function">os</span>(i<span class="tok-type">OS</span>) <span class="tok-operator">|</span><span class="tok-operator">|</span> <span class="tok-function">os</span>(tv<span class="tok-type">OS</span>)
    transformed<span class="tok-type">Layer</span><span class="tok-operator">.</span><span class="tok-function">addSublayer</span>(subview<span class="tok-operator">.</span>layer)
    <span class="tok-attribute">#endif</span>

    <span class="tok-attribute">#if</span> <span class="tok-function">os</span>(<span class="tok-type">OSX</span>)
    <span class="tok-keyword">if</span> <span class="tok-keyword">let</span> a<span class="tok-type">Layer</span> <span class="tok-operator">=</span> subview<span class="tok-operator">.</span>layer {
      transformed<span class="tok-type">Layer</span><span class="tok-operator">.</span><span class="tok-function">addSublayer</span>(a<span class="tok-type">Layer</span>)
    } <span class="tok-keyword">else</span> {
      <span class="tok-function">fatalError</span>(<span class="tok-string">"`subview.layer` == `nil`"</span>)
    }
    <span class="tok-attribute">#endif</span>
}</code></pre>
<h2>5. Perspective &amp; Rotation</h2>
<p>When the app first runs it shows in perspective.
I made a little extension:</p>
<pre><code class="language-swift"><span class="tok-keyword">public</span> <span class="tok-keyword">extension</span> <span class="tok-type">CATransform3D</span> {
  <span class="tok-keyword">static</span> <span class="tok-keyword">func</span> <span class="tok-function">somePerspectiveTransform</span>() <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">CATransform3D</span> {
    <span class="tok-keyword">var</span> perspective <span class="tok-operator">=</span> <span class="tok-type">CATransform3DIdentity</span>;
    perspective<span class="tok-operator">.</span>m<span class="tok-number">34</span> <span class="tok-operator">=</span> <span class="tok-number">-1.0</span> <span class="tok-operator">/</span> <span class="tok-number">500.0</span>;
    perspective <span class="tok-operator">=</span> <span class="tok-type">CATransform3DRotate</span>(perspective, <span class="tok-type">CGFloat</span>(<span class="tok-type">Double</span><span class="tok-operator">.</span>pi) <span class="tok-operator">/</span> <span class="tok-number">8</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>, <span class="tok-number">0</span>);
    perspective <span class="tok-operator">=</span> <span class="tok-type">CATransform3DRotate</span>(perspective, <span class="tok-type">CGFloat</span>(<span class="tok-type">Double</span><span class="tok-operator">.</span>pi) <span class="tok-operator">/</span> <span class="tok-number">8</span>, <span class="tok-number">0</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>);
    perspective <span class="tok-operator">=</span> <span class="tok-type">CATransform3DScale</span>(perspective, <span class="tok-number">0.7</span>, <span class="tok-number">0.7</span>, <span class="tok-number">0.7</span>)
    <span class="tok-keyword">return</span> perspective
  }
}</code></pre>
<p>The part: <code>perspective.m34 = -1.0 / 500.0;</code> sets the perspective.
The <code>.34</code> field of a matrix shows the amount of perspective distortion applied.
The amount <code>500</code> is often used in examples. If it were smaller, the layers would seem very close and distorted, like a fish-eye effect.</p>
<p>This is the initial transform, but we want to be able to move and rotate our cube (flattened or not) with our fingers.</p>
<p>Here’s the code:</p>
<pre><code class="language-swift"><span class="tok-keyword">public</span> <span class="tok-keyword">extension</span> <span class="tok-type">CATransform3D</span> {

  <span class="tok-keyword">func</span> <span class="tok-function">rotationFromDisplacement</span>(_ displacement<span class="tok-operator">:</span> <span class="tok-type">CGPoint</span>, side<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>, is<span class="tok-number">3</span><span class="tok-type">D</span><span class="tok-operator">:</span> <span class="tok-type">Bool</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">CATransform3D</span> {

    <span class="tok-keyword">var</span> current<span class="tok-type">Transform</span> <span class="tok-operator">=</span> <span class="tok-keyword">self</span>

    <span class="tok-keyword">let</span> total<span class="tok-type">Rotation</span><span class="tok-operator">:</span> <span class="tok-type">CGFloat</span> <span class="tok-operator">=</span> <span class="tok-function">sqrt</span>(displacement<span class="tok-operator">.</span>x <span class="tok-operator">*</span> displacement<span class="tok-operator">.</span>x <span class="tok-operator">+</span> displacement<span class="tok-operator">.</span>y <span class="tok-operator">*</span> displacement<span class="tok-operator">.</span>y)
    <span class="tok-keyword">let</span> angle<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span> <span class="tok-operator">=</span> total<span class="tok-type">Rotation</span> <span class="tok-operator">*</span> <span class="tok-operator">.</span>pi <span class="tok-operator">/</span> <span class="tok-number">180.0</span>

    <span class="tok-keyword">let</span> x<span class="tok-type">RotationFactor</span> <span class="tok-operator">=</span> displacement<span class="tok-operator">.</span>x <span class="tok-operator">/</span> angle
    <span class="tok-keyword">let</span> y<span class="tok-type">RotationFactor</span> <span class="tok-operator">=</span> displacement<span class="tok-operator">.</span>y <span class="tok-operator">/</span> angle

    <span class="tok-keyword">if</span> is<span class="tok-number">3</span><span class="tok-type">D</span> {
      current<span class="tok-type">Transform</span> <span class="tok-operator">=</span> <span class="tok-type">CATransform3DTranslate</span>(current<span class="tok-type">Transform</span>, <span class="tok-number">0</span>, <span class="tok-number">0</span>, side<span class="tok-type">Width</span> <span class="tok-operator">/</span> <span class="tok-number">2.0</span>)
    }

    <span class="tok-keyword">var</span> rotational<span class="tok-type">Transform</span> <span class="tok-operator">=</span> <span class="tok-type">CATransform3DRotate</span>(current<span class="tok-type">Transform</span>, angle,
                                                  (x<span class="tok-type">RotationFactor</span> <span class="tok-operator">*</span> current<span class="tok-type">Transform</span><span class="tok-operator">.</span>m<span class="tok-number">12</span> <span class="tok-operator">-</span> y<span class="tok-type">RotationFactor</span> <span class="tok-operator">*</span> current<span class="tok-type">Transform</span><span class="tok-operator">.</span>m<span class="tok-number">11</span>),
                                                  (x<span class="tok-type">RotationFactor</span> <span class="tok-operator">*</span> current<span class="tok-type">Transform</span><span class="tok-operator">.</span>m<span class="tok-number">22</span> <span class="tok-operator">-</span> y<span class="tok-type">RotationFactor</span> <span class="tok-operator">*</span> current<span class="tok-type">Transform</span><span class="tok-operator">.</span>m<span class="tok-number">21</span>),
                                                  (x<span class="tok-type">RotationFactor</span> <span class="tok-operator">*</span> current<span class="tok-type">Transform</span><span class="tok-operator">.</span>m<span class="tok-number">32</span> <span class="tok-operator">-</span> y<span class="tok-type">RotationFactor</span> <span class="tok-operator">*</span> current<span class="tok-type">Transform</span><span class="tok-operator">.</span>m<span class="tok-number">31</span>))

    <span class="tok-keyword">if</span> (is<span class="tok-number">3</span><span class="tok-type">D</span>) {
      rotational<span class="tok-type">Transform</span> <span class="tok-operator">=</span> <span class="tok-type">CATransform3DTranslate</span>(rotational<span class="tok-type">Transform</span>, <span class="tok-number">0</span>, <span class="tok-number">0</span>, <span class="tok-operator">-</span>side<span class="tok-type">Width</span> <span class="tok-operator">/</span> <span class="tok-number">2.0</span>);
    }

    <span class="tok-keyword">return</span> rotational<span class="tok-type">Transform</span>
  }
}</code></pre>
<p>We call it from our pan-gesture methods</p>
<pre><code class="language-swift">  <span class="tok-keyword">override</span> <span class="tok-keyword">func</span> <span class="tok-function">displacementChanged</span>(displacement<span class="tok-operator">:</span> <span class="tok-type">CGPoint</span>) {
    <span class="tok-keyword">guard</span> <span class="tok-operator">!</span>(displacement<span class="tok-operator">.</span>x <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-number">0</span> <span class="tok-operator">&amp;</span><span class="tok-operator">&amp;</span> displacement<span class="tok-operator">.</span>y <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-number">0</span>) <span class="tok-keyword">else</span> { <span class="tok-keyword">return</span> }

    <span class="tok-keyword">let</span> rotation<span class="tok-type">Transform</span> <span class="tok-operator">=</span> transformed<span class="tok-type">Layer</span><span class="tok-operator">.</span>sublayer<span class="tok-type">Transform</span><span class="tok-operator">.</span><span class="tok-function">rotationFromDisplacement</span>(displacement, side<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>, is<span class="tok-number">3</span><span class="tok-type">D</span><span class="tok-operator">:</span> is<span class="tok-type">On</span>)
    transformed<span class="tok-type">Layer</span><span class="tok-operator">.</span>sublayer<span class="tok-type">Transform</span> <span class="tok-operator">=</span> rotation<span class="tok-type">Transform</span>
  }</code></pre>
<p>We hooked up the pan-gestures prior:</p>
<pre><code class="language-swift"><span class="tok-attribute">#if</span> <span class="tok-function">os</span>(<span class="tok-type">OSX</span>)
<span class="tok-keyword">private</span> <span class="tok-keyword">func</span> <span class="tok-function">setupPanGestureRecognizer</span>() {
    <span class="tok-keyword">let</span> pan<span class="tok-type">GR</span> <span class="tok-operator">=</span> <span class="tok-type">NSPanGestureRecognizer</span>(target<span class="tok-operator">:</span> <span class="tok-keyword">self</span>, action<span class="tok-operator">:</span> <span class="tok-attribute">#selector</span>(<span class="tok-function">handlePanGesture</span>(_<span class="tok-operator">:</span>)))
    <span class="tok-function">addGestureRecognizer</span>(pan<span class="tok-type">GR</span>)
}
<span class="tok-attribute">@objc</span> <span class="tok-keyword">func</span> <span class="tok-function">handlePanGesture</span>(_ gesture<span class="tok-type">Recognizer</span><span class="tok-operator">:</span> <span class="tok-type">NSPanGestureRecognizer</span>) {
    <span class="tok-keyword">let</span> displacement<span class="tok-operator">:</span> <span class="tok-type">CGPoint</span> <span class="tok-operator">=</span> gesture<span class="tok-type">Recognizer</span><span class="tok-operator">.</span><span class="tok-function">translation</span>(<span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-keyword">self</span>)
    <span class="tok-function">handlePan</span>(displacement<span class="tok-operator">:</span> displacement, changed<span class="tok-operator">:</span> gesture<span class="tok-type">Recognizer</span><span class="tok-operator">.</span>state <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-operator">.</span>changed)
}
<span class="tok-attribute">#endif</span>

<span class="tok-attribute">#if</span> <span class="tok-function">os</span>(i<span class="tok-type">OS</span>) <span class="tok-operator">|</span><span class="tok-operator">|</span> <span class="tok-function">os</span>(tv<span class="tok-type">OS</span>)
<span class="tok-keyword">private</span> <span class="tok-keyword">func</span> <span class="tok-function">setupPanGestureRecognizer</span>() {
    <span class="tok-keyword">let</span> pan<span class="tok-type">GR</span> <span class="tok-operator">=</span> <span class="tok-type">UIPanGestureRecognizer</span>(target<span class="tok-operator">:</span> <span class="tok-keyword">self</span>, action<span class="tok-operator">:</span> <span class="tok-attribute">#selector</span>(<span class="tok-function">handlePanGesture</span>(_<span class="tok-operator">:</span>)))
    <span class="tok-function">addGestureRecognizer</span>(pan<span class="tok-type">GR</span>)
}

<span class="tok-attribute">@objc</span> <span class="tok-keyword">func</span> <span class="tok-function">handlePanGesture</span>(_ gesture<span class="tok-type">Recognizer</span><span class="tok-operator">:</span> <span class="tok-type">UIPanGestureRecognizer</span>) {
    <span class="tok-keyword">let</span> displacement<span class="tok-operator">:</span> <span class="tok-type">CGPoint</span> <span class="tok-operator">=</span> gesture<span class="tok-type">Recognizer</span><span class="tok-operator">.</span><span class="tok-function">translation</span>(<span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-keyword">self</span>)

    <span class="tok-function">handlePan</span>(displacement<span class="tok-operator">:</span> displacement, changed<span class="tok-operator">:</span> gesture<span class="tok-type">Recognizer</span><span class="tok-operator">.</span>state <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-operator">.</span>changed)

    <span class="tok-keyword">if</span> gesture<span class="tok-type">Recognizer</span><span class="tok-operator">.</span>state <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-operator">.</span>changed {
      gesture<span class="tok-type">Recognizer</span><span class="tok-operator">.</span><span class="tok-function">setTranslation</span>(<span class="tok-operator">.</span>zero, <span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-keyword">self</span>)
    }
}
<span class="tok-attribute">#endif</span></code></pre>
<p>We can also add a simple rotation transform for the rotation events/ gestures.</p>
<pre><code class="language-swift">  <span class="tok-keyword">override</span> <span class="tok-keyword">func</span> <span class="tok-function">rotationChanged</span>(radians<span class="tok-operator">:</span> <span class="tok-type">Float</span>) {
    <span class="tok-keyword">let</span> transform <span class="tok-operator">=</span> transformed<span class="tok-type">Layer</span><span class="tok-operator">.</span>sublayer<span class="tok-type">Transform</span>
    <span class="tok-keyword">let</span> rot <span class="tok-operator">=</span> <span class="tok-type">CATransform3DRotate</span>(transform, <span class="tok-type">CGFloat</span>(radians), <span class="tok-number">0</span>, <span class="tok-number">1</span>, <span class="tok-number">0</span>)
    transformed<span class="tok-type">Layer</span><span class="tok-operator">.</span>sublayer<span class="tok-type">Transform</span> <span class="tok-operator">=</span> rot
  }</code></pre>
<p>And scale, in all three axes:</p>
<pre><code class="language-swift">  <span class="tok-keyword">override</span> <span class="tok-keyword">func</span> <span class="tok-function">scaleChanged</span>(scale<span class="tok-operator">:</span> <span class="tok-type">CGFloat</span>) {
    <span class="tok-keyword">let</span> scale<span class="tok-type">Transform</span> <span class="tok-operator">=</span> <span class="tok-type">CATransform3DScale</span>(transformed<span class="tok-type">Layer</span><span class="tok-operator">.</span>sublayer<span class="tok-type">Transform</span>, scale, scale, scale)
    transformed<span class="tok-type">Layer</span><span class="tok-operator">.</span>sublayer<span class="tok-type">Transform</span> <span class="tok-operator">=</span> scale<span class="tok-type">Transform</span>
  }</code></pre>
<p>The <code>tap</code> turns on and off our 3D transform</p>
<pre><code class="language-swift">  <span class="tok-keyword">override</span> <span class="tok-keyword">func</span> <span class="tok-function">tapHappened</span>() {
    <span class="tok-function">set3DCube</span>(on<span class="tok-operator">:</span> is<span class="tok-type">On</span>)
  }</code></pre>
<p>Here’s the 3D cube code</p>
<pre><code class="language-swift">  <span class="tok-keyword">func</span> <span class="tok-function">set3DCube</span>(on<span class="tok-operator">:</span> <span class="tok-type">Bool</span>) {
    side<span class="tok-number">4.</span>layer<span class="tok-operator">.</span>z<span class="tok-type">Position</span> <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span> <span class="tok-operator">:</span> <span class="tok-number">1</span>
    side<span class="tok-number">1.</span>layer<span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">1</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>) <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
    side<span class="tok-number">2.</span>layer<span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">2</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>) <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
    side<span class="tok-number">3.</span>layer<span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">3</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>) <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
    side<span class="tok-number">4.</span>layer<span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">4</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>) <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
    side<span class="tok-number">5.</span>layer<span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">5</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>) <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
    side<span class="tok-number">6.</span>layer<span class="tok-operator">.</span>transform <span class="tok-operator">=</span> on <span class="tok-operator">?</span> <span class="tok-type">CATransform3D</span><span class="tok-operator">.</span><span class="tok-function">transformFor3DCubeSide</span>(<span class="tok-number">6</span>, z<span class="tok-type">Width</span><span class="tok-operator">:</span> <span class="tok-type">CACube3DView</span><span class="tok-operator">.</span>side<span class="tok-type">Width</span>) <span class="tok-operator">:</span> <span class="tok-type">CATransform3DIdentity</span>
  }</code></pre>
<p>We either set the <code>identity transform</code>, which means <code>no transform</code>, to our cube sides, or the transform appropriate for that particular side.</p>
<h2>6. macOS Troubles</h2>
<p>I suppose I need to do further investigation in how <code>macOS</code> treats layers of <code>NSView</code>, for this little experiment is not working on the <code>macOS</code>, yet.
Here’s how the flattened cube looks on the <code>macOS</code></p>
<p><img src="https://aleahim.com/images/cacube/12_cube_macOS_flat_messed_up.png" alt="A macOS view of the six tiles as parallel upright panels in a row, numbered 6, 5, 4, 3, 2 and 1 from the left, each in thin outlines on a dark grey floor: the flat layout going wrong."></p>
<p>So, the positioning of the layers is not respected.</p>
<p>And here is the cube in 3D:</p>
<p><img src="https://aleahim.com/images/cacube/13_cube_macOS_3D_messed_up.png" alt="A macOS view of the cube’s tiles wrongly placed: 3 green and 1 blue behind, 4 purple and 2 red standing upright in the middle, 6 yellow and 5 grey lying on the floor, inside a thin wire box."></p>
<p>I did try to force the <code>isGeometryFlipped = true</code> everywhere. Anyway this needs more work.</p>
<p>If you want to help with the <code>macOS</code> implementation, please, be my guest.</p>
<p>Here’s a link to a Codeberg repo with the source code:
<a href="https://codeberg.org/Mihaela/CubeIn3DWithCoreAnimation">Core Animation 3D Cube</a></p>]]></content:encoded>
</item>
</channel>
</rss>
