<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Derived Data</title><description>A blog about Apple platforms, Swift, SwiftUI, Xcode, and related developer topics by Reda Lemeden.</description><link>https://redalemeden.com/</link><lastBuildDate>Wed, 15 Apr 2026 21:05:33 GMT</lastBuildDate><image><title>Reda Lemeden</title><url>https://redalemeden.com/icon-touch.png</url><link>https://redalemeden.com</link></image><item><title>A Feel-Good Refactor</title><link>https://redalemeden.com/derived-data/2021/a-feel-good-refactor/</link><guid isPermaLink="true">https://redalemeden.com/derived-data/2021/a-feel-good-refactor/</guid><pubDate>Sun, 21 Feb 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you are using Combine&apos;s &lt;code&gt;Just&lt;/code&gt;, &lt;code&gt;Fail&lt;/code&gt;, or &lt;code&gt;Result.publisher&lt;/code&gt; as much as I do
to mock publishers for SwiftUI&apos;s previews and tests, chances are you have grown
tired of manually setting either the output or the failure types, then erasing
to &lt;code&gt;AnyPublisher&lt;/code&gt; in every occurrence.&lt;/p&gt;
&lt;p&gt;Today I decided that it was time to honor the rule of three (or &lt;em&gt;thirty eight&lt;/em&gt;?)
and come up with something better. For one, we can heavily lean on Swift&apos;s &lt;a href=&quot;https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html#ID322&quot;&gt;type inference&lt;/a&gt;
to improve the API at the call site. And while we&apos;re at it, we can make it
easier to remember by using a similar syntax to handle both success and failure
scenarios.&lt;/p&gt;
&lt;p&gt;Since the goal here is to create a type-erased publisher that emits either a value
or an error then completes, we can call the helper &lt;em&gt;&quot;once&quot;&lt;/em&gt;. As for the
implementation, we have a couple of options: define a static function on
&lt;code&gt;Publisher&lt;/code&gt;, or create a custom &lt;code&gt;Publisher&lt;/code&gt; type. Since the latter would still
require type-erasure at the call site, I chose to go with the former.&lt;/p&gt;
&lt;p&gt;Let&apos;s start with the far more common value-emitting path.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public extension Publisher {
  static func once&amp;lt;T, U: Error&amp;gt;(
   _ value: T,
    failAs error: U.Type // 1
  ) -&amp;gt; AnyPublisher&amp;lt;T, U&amp;gt; {
    Just(value)
      .setFailureType(to: U.self)
      .eraseToAnyPublisher()
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This does the job, but having to specify the error type (1) every time takes
away some of the &lt;em&gt;feel-goodness&lt;/em&gt; of this solution. Luckily, Swift&apos;s type
inference comes to the rescue. Time for take 2!&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static func once&amp;lt;T, U: Error&amp;gt;(
  _ value: T
) -&amp;gt; AnyPublisher&amp;lt;T, U&amp;gt; {
  Just(value)
    .setFailureType(to: U.self)
    .eraseToAnyPublisher()
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The type of the return value should be enough to identify the publisher&apos;s
failure type. For cases where there isn&apos;t enough type information at the call
site, we can keep the first iteration around to avoid the need for explicit
types when assigning values—but that&apos;s purely a matter of preference.&lt;/p&gt;
&lt;p&gt;With the happy path case behind us, let&apos;s do the same for the failure-emitting
case.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static func once&amp;lt;T, U: Error&amp;gt;( // 1
  failing error: U // 2
) -&amp;gt; AnyPublisher&amp;lt;T, U&amp;gt; {
  Fail(
    outputType: T.self,
    failure: error
  )
  .eraseToAnyPublisher()
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I chose to keep the same method name (1) to streamline the API at the call site.
Unfortunately this means an additional keyword is needed to help the compiler
tell them apart. I went with &lt;code&gt;failing&lt;/code&gt; (2) on the spur of the moment, but
anything would do the job. If call site uniformity is a non-goal, then using
&lt;code&gt;just&lt;/code&gt;/&lt;code&gt;fail&lt;/code&gt; to match the Combine publishers would be preferable.&lt;/p&gt;
&lt;p&gt;As a parting bonus, we can throw in an additional helper for publishers where
the output value is &lt;code&gt;Void&lt;/code&gt;; quite common for write operations and &lt;code&gt;PUT&lt;/code&gt;/&lt;code&gt;DELETE&lt;/code&gt;
endpoints.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static func once&amp;lt;U: Error&amp;gt;() -&amp;gt; AnyPublisher&amp;lt;Void, U&amp;gt; {
  once((), failAs: U.self)
}

static func once&amp;lt;U: Error&amp;gt;(
  failing error: U
) -&amp;gt; AnyPublisher&amp;lt;Void, U&amp;gt; {
  once(Void.self, failing: error)
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Armed with these new tools, mocking publishers is now as easy as calling
&lt;code&gt;once()&lt;/code&gt; and &lt;code&gt;once(failing:)&lt;/code&gt; with the value or error respectively.&lt;/p&gt;
&lt;p&gt;Here&apos;s an example from the codebase that prompted me to write this post:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;let cache = Cache(
  upsert: { value in // -&amp;gt; AnyPublisher&amp;lt;Value, CachingError&amp;gt; 
    Just(value)
      .setFailureType(to: CachingError.self)
      .eraseToAnyPublisher()
  },
  deleteOutdated: { // -&amp;gt; AnyPublisher&amp;lt;Int, CachingError&amp;gt;
    Just(2)
      .setFailureType(to: CachingError.self)
      .eraseToAnyPublisher()
  },
  deleteAll: { // -&amp;gt; AnyPublisher&amp;lt;Int, CachingError&amp;gt;
    Fail(
      outputType: Int.self,
      failure: CachingError.nothingToDelete
    )
  }
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And here is the same section after the refactor:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;let cache = Cache(
  upsert: { .once($0) }, // (Item) -&amp;gt; AnyPublisher&amp;lt;Value, Error&amp;gt;
  deleteOutdated: { .once(2) }, // () -&amp;gt; AnyPublisher&amp;lt;Int, Error&amp;gt;
  deleteAll: { .once(failing: .nothingToDelete) } // () -&amp;gt; AnyPublisher&amp;lt;Int, Error&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, tell me which scores higher in the &lt;em&gt;feel-good&lt;/em&gt; department?&lt;/p&gt;
</content:encoded></item><item><title>Debugging SwiftUI: Trials and Tribulations</title><link>https://redalemeden.com/derived-data/2020/debugging-swiftui-trials-and-tribulations/</link><guid isPermaLink="true">https://redalemeden.com/derived-data/2020/debugging-swiftui-trials-and-tribulations/</guid><pubDate>Fri, 30 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I have been using &lt;a href=&quot;https://developer.apple.com/xcode/swiftui/&quot;&gt;SwiftUI&lt;/a&gt; since
day one, on both client and side projects. It&apos;s an incredibly refreshing way of
coding interfaces for Apple devices, but it&apos;s far from being wrinkle-free. The
framework&apos;s bold ambitions are sometimes hampered by subpar debugging tools and
arcane, seemingly random limitations.&lt;/p&gt;
&lt;p&gt;I previously
&lt;a href=&quot;https://redalemeden.com/blog/2020/this-week-i-learned-24#programming&quot;&gt;wrote&lt;/a&gt;
about a SwiftUI bug that gave me quite a run for my money:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The stack trace isn’t of much help and no amount of view hierarchy tweaks got
rid of it entirely. Initially I was under the impression that either my code
or one of my external dependencies were doing something horribly wrong, but
&lt;a href=&quot;https://steipete.com/posts/state-of-swiftui/&quot;&gt;this post&lt;/a&gt; from Peter
Steinberger made me realize that it is a rather widespread issue.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Since I didn’t manage to reproduce it on a particular test device at the time, I
assumed it’s yet another simulator quirk. But a little over a month later, the
same bug reared its ugly head on a test device. Fun times!&lt;/p&gt;
&lt;p&gt;The app in question uses tab navigation where the first tab is always
accessible, while the second tab shows different content depending on whether
the user is signed in to their account or not. The view code looked roughly like
this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;TabView {
  Home()
    .tabItem { /* ... */ }
    .tag { /* ... */ }

  if isSignedIn {
    Profile()
      .tabItem { /* ... */ }
      .tag { /* ... */ }
  } else {
    SignIn()
      .tabItem { /* ... */ }
      .tag { /* ... */ }
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To avoid the &lt;code&gt;isSignedIn&lt;/code&gt; boolean check in multiple modifiers, I opted for an
&lt;code&gt;if-else&lt;/code&gt; block with separate views and &lt;code&gt;tabItem&lt;/code&gt; modifiers.[^1] Except that
didn’t seem to sit right with SwiftUI for some reason. The app launches and
displays the content of the first tab exactly as intended. But when I switch
tabs—or god forbid, sign in or out—the app crashes with this cryptic error
message:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[error] precondition failure: invalid size for indirect attribute: &amp;lt;number&amp;gt; vs &amp;lt;number&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The call stack points exclusively to SwiftUI internals, with the last call
referring to a certain
&lt;code&gt;AG::Graph&lt;/code&gt;—&lt;a href=&quot;https://steipete.com/posts/state-of-swiftui/#swiftui-attributegraph-crashes&quot;&gt;responsible&lt;/a&gt;
for holding the view tree and diffing it. As far as debugging goes, this is
very, &lt;em&gt;very&lt;/em&gt; little to work with.&lt;/p&gt;
&lt;p&gt;With my hands tied, I briefly considered resurrecting the &lt;code&gt;UITabBarController&lt;/code&gt;
wrapper I used prior to WWDC, especially since I didn’t manage to make a
reproducible test case or submit a feedback to Apple. At first, I spent an
inordinate amount of time tweaking the view hierarchies of the profile and
sign-in screens themselves, with varying—and rather inconsistent—levels of
success. I ran out of both time and patience, so I moved on to other things to
not stall the project any further. Weeks later, I came back to the problematic
screen—pitchfork in hand—ready to gut the entire tab navigation and replace it
with a custom-made solution. I had had enough.&lt;/p&gt;
&lt;p&gt;But then came the proverbial aha moment: what if the conditional check took
place &lt;em&gt;inside&lt;/em&gt; the second tab, instead of &lt;em&gt;around&lt;/em&gt; it?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;TabView {
  Home()
    .tabItem { /* ... */ }
    .tag { /* ... */ }

  ProfileOrSignIn(isSignedIn: $isSignedIn)
    .tabItem { /* ... */ }
    .tag { /* ... */ }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And &lt;em&gt;just&lt;/em&gt; like that, the crasher was gone. Squashed into oblivion.&lt;/p&gt;
&lt;p&gt;If this sounds dumb, it’s because it is. At no point did the compiler chastise
me for doing something I wasn&apos;t supposed to do. And to make matters worse, the
documentation doesn&apos;t mention anything related to... wait, what documentation?&lt;/p&gt;
&lt;p&gt;It’s a bittersweet feeling when you fix a bug in a non-deterministic, haphazard
way. On one hand you are elated you’ve managed to fix it at all. On the other,
you feel somewhat powerless and insecure about your ability to handle similar
situations in the future. I adore SwiftUI, but moments like these give me a good
dose of anticipatory anxiety—the kind that erodes trust and dampens the thrill of
being at the bleeding edge.&lt;/p&gt;
&lt;p&gt;[^1]: As an aside, apps that greet users with a sign up screen are generally
trash. You don&apos;t ask prospective tenants to sign the contract at the door
before they&apos;ve even seen the apartment.&lt;/p&gt;
</content:encoded></item><item><title>How I Use Document Tabs in Xcode 12</title><link>https://redalemeden.com/derived-data/2020/xcode-12-document-tabs/</link><guid isPermaLink="true">https://redalemeden.com/derived-data/2020/xcode-12-document-tabs/</guid><pubDate>Thu, 03 Sep 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The new &lt;em&gt;document tabs&lt;/em&gt; in Xcode 12 caught me off-guard more than once at first,
but as soon as I figured out how they work, I started to enjoy using them.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;For instance, in server-side projects I am typically dealing with half a dozen
files related to the same area or feature; the model itself, the repository,
migrations, tests, mocks, etc. Before, I used separate window tabs for each
&quot;topic&quot;, but now I rely heavily on document tabs to fill that need. My current
setup is something roughly like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;I usually keep 3 window tabs in every project: &lt;em&gt;development&lt;/em&gt;, &lt;em&gt;testing&lt;/em&gt;, and
&lt;em&gt;debugging&lt;/em&gt;. I occasionally create break-out window tabs for self-contained
tasks like refactoring, reading the source code of a dependency, etc.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the development window tab, I use vertical area splits for the different
topics I am actively working on. Usually these correspond to a model file and
its satellite types. I start with one then add or remove splits as needed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Inside each area, I use the new &lt;em&gt;document tabs&lt;/em&gt; to keep all the related files
open, enabling quick tab switching using the keyboard shortcut &amp;lt;kbd&amp;gt;cmd&amp;lt;/kbd&amp;gt; + &amp;lt;kbd&amp;gt;shift&amp;lt;/kbd&amp;gt; + &amp;lt;kbd&amp;gt;[&amp;lt;/kbd&amp;gt; or &amp;lt;kbd&amp;gt;]&amp;lt;/kbd&amp;gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I use horizontal splits when I need to look at different files in the same
topic. An example would be the model and its migration file in server-side, or
a view and its state object in SwiftUI.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I reason better about code when I can see several related files at the same
time, and document tabs give me an even more effective way to achieve that.&lt;/p&gt;
</content:encoded></item><item><title>Mattt on WWDC 2020</title><link>https://redalemeden.com/derived-data/2020/mattt-wwdc-2020/</link><guid isPermaLink="true">https://redalemeden.com/derived-data/2020/mattt-wwdc-2020/</guid><pubDate>Sun, 28 Jun 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;It&apos;s refreshing to see &lt;a href=&quot;https://nshipster.com/wwdc-2020/&quot;&gt;Mattt&apos;s reasoned take&lt;/a&gt;
amidst all the attention-seeking headlines this week:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;As it turns out, going fully remote wasn’t merely good enough — it was, in
many ways, superior to the original thing.  [...] Sessions are tight and
well-paced. Rather than stretching or cramming content into a fixed time slot,
they’re as long as they need to be.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This definitely echoes my impressions. As someone who mostly followed along from
home in the past, not only did I not miss much this year, but I got treated to a
much improved remote experience.&lt;/p&gt;
&lt;p&gt;Mattt also brings up the topic of Excitement—or &lt;em&gt;hype&lt;/em&gt;, as I often call it—and
productivity:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Here’s the thing about excitement: It’s kryptonite to developers. Excitement
messes with our ability to focus on one thing, which is already a big struggle
for a lot of us (myself included). When you’re excited, it’s almost impossible
to get anything done.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is true for any endeavor, but especially so for software development.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;There are plenty of voices in the community who are echoing this excitement. I
can’t add anything to that discussion. And besides, that’s not really where my
head’s at right now.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The official Apple content generates enough sense of &amp;lt;abbr title=&quot;Fear of
Missing Out&quot;&amp;gt;FOMO&amp;lt;/abbr&amp;gt; as it is. Combining that with a firehose of &lt;em&gt;What&apos;s new
in X&lt;/em&gt; blog posts, podcasts, YouTube videos, and tweets doesn&apos;t help much as far
as I am concerned.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;It’s been an exciting week, so take a moment to collect yourself. Go on a
walk. Take a hike. (Be safe about it.) Do whatever you need to break free of
the “reality distortion field”. Once you do, you’ll have the necessary
distance to determine what new technologies you should pay attention to and
what you can ignore for now.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Solid advice, WWDC or otherwise.&lt;/p&gt;
</content:encoded></item><item><title>Early Lessons in Adopting SwiftUI</title><link>https://redalemeden.com/derived-data/2019/swift-ui-early-lessons/</link><guid isPermaLink="true">https://redalemeden.com/derived-data/2019/swift-ui-early-lessons/</guid><pubDate>Fri, 02 Aug 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;We&apos;ve been using SwiftUI day in and day out since the first beta to build a
non-trivial app at work---a bold move, but one that makes me like my job. Here
are some lessons I&apos;ve learned:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Stick to standard navigation. As unstable as the APIs are for the time being,
this will spare you the layout and accessibility headaches that come with
custom transitions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Always investigate whether your UI can be implemented as a list view. It
handles dynamic type, dark mode, and other accessibility features out of the
box, and will likely look more polished as a result.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make good use of section headers and footers in &lt;code&gt;List&lt;/code&gt;. Unlike &lt;code&gt;UITableView&lt;/code&gt;,
these are much easier to set up in SwiftUI&apos;s declarative syntax. They can be
used for empty states, search fields, sorting controls, etc.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Embrace the current limitations of the framework. If you have to fight it at
every turn to get the result you want, consider taking a different route where
you don&apos;t have to do that. You can revisit the same challenge later as the
framework matures.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Don’t use hard coded colors, i.e. the RGB initializer. Use system tint colors
or asset catalogs instead, and stay clear of white and black as they don&apos;t
adapt to appearance modes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Pay attention to the methods used to pass data down to and up from subviews.
It’s easy to use the wrong method and the error won’t be very helpful. Spend
some time to understand the difference between &lt;code&gt;@State&lt;/code&gt;, &lt;code&gt;@Binding&lt;/code&gt;,
&lt;code&gt;@ObservedObject&lt;/code&gt;, and &lt;code&gt;@EnvironmentObject&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Speaking of compiler errors, split your view hierarchy using variables,
methods, and separate view structs to make the wide of the mark error messages
slightly more relevant and helpful.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Extract reoccurring view modifier chains into custom modifiers to DRY up the
code. It&apos;s a bit more work that I anticipated, but it&apos;s worth it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;UIKit appearance helpers still work in SwiftUI. Call them from within the
&lt;code&gt;init()&lt;/code&gt; method of the view when needed. For instance, this is the only method
to remove the opaque background from a &lt;code&gt;List&lt;/code&gt; as of now.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SwiftUI is still very rough around the edges, so keep your cool and stay
hydrated.🥤&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
</content:encoded></item><item><title>Swift&apos;s Killer Feature</title><link>https://redalemeden.com/derived-data/2019/swift-killer-feature/</link><guid isPermaLink="true">https://redalemeden.com/derived-data/2019/swift-killer-feature/</guid><pubDate>Tue, 18 Jun 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Since its release 5 years ago, Swift has matured a great deal as a programming
language, both in terms of stability and expressive power. Its concise syntax
and type safety have been largely celebrated within the Apple developer
community, and increasingly noticed outside of it. But, as it is the case with
similar transitions, not everything is hunky-dory.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In addition to the source breaking changes that soured the language earlier on,
Swift is often criticized for lacking an indisputable selling point compared to
what was there before it (Cocoa and Objective-C), and what came after it
(JavaScript cross-platform frameworks).&lt;/p&gt;
&lt;p&gt;Unfair as it may sound, programming languages are often evaluated based on their
ecosystem, not on their intrinsic merits. In the eyes of many, Swift is
indissociable from Apple and their platform UI frameworks, for better or for
worse. The mismatch between Cocoa APIs and Swift language features has been
brought up again and again in discussions about its appeal as a replacement for
Objective-C.&lt;/p&gt;
&lt;p&gt;Expressiveness and type safety can certainly keep a handful of enthusiastic
developers engaged, but it won’t be enough to sustain Swift’s momentum on the
long run. As much as some of us hate to admit, the competition is colossal on
the server and scripting side of things, and it’s getting uncomfortably stronger
on the native platform front.&lt;/p&gt;
&lt;p&gt;On top of that, the &lt;em&gt;write-preview-debug&lt;/em&gt; development cycle that we’ve been
dealt since the dawn of Cocoa is considered sluggish and tedious by today’s
standards. A liability that’s long overdue for reconsideration. To make matters
worse, Apple&apos;s UI frameworks haven’t converged fast enough to alleviate some of
these issues---we are still required to implement half a dozen methods for each
platform to display a plain table view.&lt;/p&gt;
&lt;p&gt;This state of affairs has pushed many to adventure outside first-party fences in
search of more exotic alternatives, while the holdouts stuck to their &lt;s&gt;guns&lt;/s&gt;
bows and arrows in the absence of a clear-cut perk of leaving their
tried-and-true programming language behind[^1].&lt;/p&gt;
&lt;p&gt;But all of this is bound to change.&lt;/p&gt;
&lt;p&gt;During this past WWDC, Apple introduced
&lt;em&gt;&lt;a href=&quot;https://developer.apple.com/xcode/swiftui/&quot;&gt;SwiftUI&lt;/a&gt;&lt;/em&gt;---a modern, universal
framework for building user interfaces across their platforms. And it’s &lt;em&gt;packing
quite a punch.&lt;/em&gt; SwiftUI is declarative, reactive, and ready to take us places;
the killer feature that Swift &lt;em&gt;deserved&lt;/em&gt; all along. Not only is it tightly
integrated with the language, but it’s also pushing it forward by providing a
use case for new additions such as &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/9992cf3c11c2d5e0ea20bee98657d93902d5b174/proposals/XXXX-function-builders.md&quot;&gt;function builders&lt;/a&gt;
and &lt;a href=&quot;https://github.com/DougGregor/swift-evolution/blob/property-wrappers/proposals/0258-property-wrappers.md&quot;&gt;property wrappers&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Even though we have barely scratched the surface of SwiftUI since its
announcement, it’s already winning the hearts of large swaths of developers,
myself included. I don&apos;t have a shred of doubt that this is the future of UI
programming on Apple platforms, and I am thrilled to witness, and be part of,
this transition.&lt;/p&gt;
&lt;p&gt;[^1]: Part of me appreciates the prudent approach with regard to adopting new
technology that’s yet to prove itself. Another part of me fails to see the
point of swimming against the current in a predominantly closed platform
where a single company gets to call the shots.&lt;/p&gt;
</content:encoded></item><item><title>Units in Foundation</title><link>https://redalemeden.com/derived-data/2016/units-in-foundation/</link><guid isPermaLink="true">https://redalemeden.com/derived-data/2016/units-in-foundation/</guid><pubDate>Sun, 04 Dec 2016 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Starting iOS 10 and macOS 10.12, &lt;em&gt;Foundation&lt;/em&gt; supports units and measurements
out of the box, in the form of
&lt;a href=&quot;https://developer.apple.com/reference/foundation/unit&quot;&gt;(NS)Unit&lt;/a&gt; and
&lt;a href=&quot;https://developer.apple.com/reference/foundation/nsmeasurement&quot;&gt;(NS)Measurement&lt;/a&gt;
respectively. Let&apos;s take a look at how they work.&lt;/p&gt;
&lt;p&gt;Note: All code snippets below are written in &lt;strong&gt;Swift 3.0&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;To get started, let&apos;s define a measurement. To do that, you have to pass a
&lt;em&gt;value&lt;/em&gt; and a &lt;em&gt;unit&lt;/em&gt; to the initializer:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import Foundation

let snorlaxWeight = Measurement(value: 460, unit: UnitMass.kilograms)
// -&amp;gt; 460.0 kg
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can then effortlessly convert the measurement to another unit:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;let snorlaxWightInImperial = snorlaxWeight.converted(to: .pounds)
// -&amp;gt; 1014.12723328454 lb
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can also define your own unit by extending one of the default
&lt;a href=&quot;https://developer.apple.com/reference/foundation/dimension&quot;&gt;&lt;em&gt;dimensions&lt;/em&gt;&lt;/a&gt;
available:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;extension UnitMass {
  static let snorlax = UnitMass(symbol: &quot;snorlax&quot;, converter: UnitConverterLinear(coefficient: 460))
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The converter is used to transform the measurement from any given unit to the
base unit of the dimension; Kilograms in the case of &lt;code&gt;UnitMass&lt;/code&gt;. You can inspect
the base unit of any dimension by calling &lt;code&gt;baseUnit()&lt;/code&gt; on it.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;UnitMass.baseUnit()
// -&amp;gt; kg
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once defined, your custom unit can be used alongside the pre-defined ones:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;let statueOfLibertyMass = Measurement(value: 225_000, unit: UnitMass.kilograms)
let statueOfLibertyMassInSnorlax = statueOfLibertyMass.converted(to: .snorlax)
// -&amp;gt; 489.130434782609 snorlax
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can also define a custom dimension of units by subclassing &lt;code&gt;Dimension&lt;/code&gt; if
necessary. Here is an example that defines a new &lt;code&gt;UnitDataRate&lt;/code&gt; class for
measuring data transfer rates, often used in Internet speed tests:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class UnitDataRate: Dimension {
  static let kilobitPerSecond = UnitDataRate(symbol: &quot;kbps&quot;, converter: UnitConverterLinear(coefficient: 1))
  static let megabitPerSecond = UnitDataRate(symbol: &quot;Mbps&quot;, converter: UnitConverterLinear(coefficient: 1_000))
  static let gigabitPerSecond = UnitDataRate(symbol: &quot;Gbps&quot;, converter: UnitConverterLinear(coefficient: 1_000_000))

  override class func baseUnit() -&amp;gt; UnitDataRate {
    return .megabitPerSecond
  }
}

let speed = Measurement(value: 100, unit: UnitDataRate.megabitPerSecond)
let speedInKpbs = speed.converted(to: .kilobitPerSecond)

// -&amp;gt; 100000 kbps
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Learn More&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2016/238/&quot;&gt;WWDC session 238&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://oleb.net/blog/2016/07/measurements-and-units/&quot;&gt;Measurements and Units in Foundation&lt;/a&gt; by Ole
Begemann.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://videos.raywenderlich.com/screencasts/ios-10-measurements-units&quot;&gt;iOS 10: Measurements &amp;amp; Units Screencast&lt;/a&gt;
by Sam Davies.&lt;/li&gt;
&lt;/ul&gt;
</content:encoded></item><item><title>Swift 3 Access Control</title><link>https://redalemeden.com/derived-data/2016/swift-3-access-control/</link><guid isPermaLink="true">https://redalemeden.com/derived-data/2016/swift-3-access-control/</guid><pubDate>Thu, 29 Sep 2016 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Swift 3 introduced finer-grained control over what can access what in your code.
The addition of 2 keywords made things less obvious, however. Here is a
cheatsheet to help with the transition:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Private&lt;/strong&gt;: Entity can only be accessed within the same scope it was defined
in. A &lt;code&gt;private&lt;/code&gt; class can only be subclassed by another &lt;code&gt;private&lt;/code&gt; class
defined in the same scope.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;File private&lt;/strong&gt;: Entity can only be accessed within the same file. You can
subclass &lt;code&gt;fileprivate&lt;/code&gt; classes and override their &lt;code&gt;fileprivate&lt;/code&gt; methods and
properties.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Internal&lt;/strong&gt;: Entity can only be accessed within the same module, i.e. app or
framework target. This is the &lt;em&gt;default&lt;/em&gt; if no access keyword is specified. You
can subclass classes and override their non-private methods and properties.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Public&lt;/strong&gt;: Entity can be accessed from within other modules. Classes cannot
be subclassed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Open&lt;/strong&gt;: Entity can be accessed from within other modules. Classes can be
subclassed in other modules if they are marked as &lt;code&gt;open&lt;/code&gt;. Each method and
property needs to be marked as &lt;code&gt;open&lt;/code&gt; to be overridable in subclasses.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
</content:encoded></item><item><title>tvOS HIG: Too Long; Didn&apos;t Read</title><link>https://redalemeden.com/derived-data/2015/tvos-hig-tldr/</link><guid isPermaLink="true">https://redalemeden.com/derived-data/2015/tvos-hig-tldr/</guid><pubDate>Mon, 05 Oct 2015 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I often joke about the
&lt;a href=&quot;https://developer.apple.com/tvos/human-interface-guidelines/&quot;&gt;HIG&lt;/a&gt; being an
acronym for &lt;em&gt;Highly Ignored Guidelines&lt;/em&gt;. This is an effort to change that, at
least for tvOS.&lt;/p&gt;
&lt;p&gt; &lt;em&gt;The user interface of tvOS.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Glossary&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Click&lt;/strong&gt;. One-finger quick press on the center of the touch surface. The
primary way of triggering actions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Click-and-hold&lt;/strong&gt;. One-finger long press on the center of the touch surface.
Used to trigger context-specific actions, like entering edit mode.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Focus&lt;/strong&gt;. The state of the currently selected interface element.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Parallax&lt;/strong&gt;. An effect applied to focused app icons and content elements
using multiple layered images.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Siri Remote&lt;/strong&gt;. The Siri-enabled remote used as the primary input method for
Apple TV. It comes with 6 buttons, a touch surface, an accelerometer, and a
gyroscope.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Swipe&lt;/strong&gt;. One-finger press followed by a quick movement in any direction on
the touch surface. Used to move focus vertically or horizontally.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Tap&lt;/strong&gt;. One-finger quick press on one of the four directions (top, right,
bottom, left) of the touch surface. Used for single-item directional
navigation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Top Shelf&lt;/strong&gt;. The area above the first row of apps where featured content of
the focused app appears.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Update&lt;/em&gt;: My colleague &lt;a href=&quot;https://twitter.com/jacknutting&quot;&gt;Jack Nutting&lt;/a&gt; pointed
out that clicks require you to press the touch surface until it clicks, whereas
taps don&apos;t.&lt;/p&gt;
&lt;h2&gt;General&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Design with multiple simultaneous users in mind.&lt;/li&gt;
&lt;li&gt;Prefer showing old data to no data at all.&lt;/li&gt;
&lt;li&gt;Avoid excessive animation.&lt;/li&gt;
&lt;li&gt;Avoid using alerts unless it’s for a critical user decision. When you do,
provide no more than two choices.&lt;/li&gt;
&lt;li&gt;Don’t display your logo throughout the app UI.&lt;/li&gt;
&lt;li&gt;Use the system video player to get advantage of all its interactive features.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Focus&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Make focus obvious using labels, transforms, and other effects.&lt;/li&gt;
&lt;li&gt;Use parallax on focused elements to make the UI more responsive to user
interaction.&lt;/li&gt;
&lt;li&gt;Prefer light backgrounds so that focus shadows remain visible.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Controls&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Keep the difference between click and tap in mind. See the
&lt;a href=&quot;#glossary&quot;&gt;glossary&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Avoid using taps for triggering actions other than navigation.&lt;/li&gt;
&lt;li&gt;Avoid using standard gestures to perform non-standard actions.&lt;/li&gt;
&lt;li&gt;Avoid defining new gestures to perform standard actions.&lt;/li&gt;
&lt;li&gt;Make sure your controller-compatible game works with the remote as well.&lt;/li&gt;
&lt;li&gt;Always enable the Play/Pause button on the Siri Remote. If you are running out
of ideas, make it at least perform a click.&lt;/li&gt;
&lt;li&gt;Use gestures to move focus, not content. For instance, a left swipe would move
focus to the left, making the content move to the right.&lt;/li&gt;
&lt;li&gt;Use gestures to move content when displayed full-screen. For instance. a left
swipe on a full-screen image would move the image to the left.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Navigation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Use the tab bar for the main navigation of your app.&lt;/li&gt;
&lt;li&gt;Allow your users to navigate back to the previous screen or out of your
app/game using the Menu button.&lt;/li&gt;
&lt;li&gt;Don&apos;t display a back button.&lt;/li&gt;
&lt;li&gt;Keep your content structure simple for easier navigation.&lt;/li&gt;
&lt;li&gt;Prefer text, more specifically nouns and verbs for your tab titles.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Visual Design&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Design your interface for a 1920 x 1080 pixels (16:9) screen in mind.&lt;/li&gt;
&lt;li&gt;Use @1x resolution for all image assets.&lt;/li&gt;
&lt;li&gt;Use an opaque background layer when making your layered images.&lt;/li&gt;
&lt;li&gt;Provide at least one static Top Shelf image (1920px by 720px) if you don’t
have any dynamic content to showcase.&lt;/li&gt;
&lt;li&gt;Use the sRGB color space.&lt;/li&gt;
&lt;li&gt;Favor muted color for better results on highly saturated TVs.&lt;/li&gt;
&lt;li&gt;Prefer top-to-bottom, light-to-dark gradients.&lt;/li&gt;
&lt;li&gt;Prefer horizontal layouts.&lt;/li&gt;
&lt;li&gt;Leave 60 pixels on the top and bottom, and 90 pixels on the right and left as
padding around the edges of the screen.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Text&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Use San Francisco Text for text 39 points or smaller, and San Francisco
Display for text that&apos;s 40 points or larger.&lt;/li&gt;
&lt;li&gt;Put text in the top-most layer of your layered images.&lt;/li&gt;
&lt;li&gt;Use the built-in text styles to take advantage of features like Dynamic Type.&lt;/li&gt;
&lt;li&gt;Use title-case in your text buttons.&lt;/li&gt;
&lt;li&gt;Avoid combining both icons and text in buttons.&lt;/li&gt;
&lt;li&gt;Try to limit text-input in your app since typing on the Apple TV can be
tedious.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;App Icon&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Use a layered image (2-5 layers) for your app icon (1280px by 768px for large
version and 400px by 240px for the small one).&lt;/li&gt;
&lt;li&gt;Leave a padding around the content of your foreground layers.&lt;/li&gt;
&lt;li&gt;Don’t include screenshots in your app icon.&lt;/li&gt;
&lt;li&gt;Avoid text in your app icon, unless it’s part of the brand.&lt;/li&gt;
&lt;/ul&gt;
</content:encoded></item></channel></rss>