CommentComment

This is the last issue of Not only Swift for 2023, and to wrap up the year 2023, I thought I'd run an entire issue with the articles that you liked best. This is an experiment, so feel free to let me know how you like this format - just hit the reply button!

So - without further ado, here are the most clicked links of 2023.

BTW - I noticed that I published 26 issues this year, so maybe I should call the newsletter "Not only Swift fortnightly".

Thanks for being a subscriber, it really means a lot to me! When I started this newsletter, I decided to keep it going as long as there is growth - and so far, the subscriber count has only gone up! If you like this newsletter, recommend it to your friends and colleagues to keep me going :-)

Peter  

What I am working on

Styling SwiftUI Views - How does view styling work?

I am sure you have used SwiftUI's styling APIs before - for example to configure the look and feel of List views. But how does this work, and how can we use view styling to our advantage?

In this series, I will answer these questions, and show you how you can create new custom styles for SwiftUI's views such as Toggle, Button, and GroupBox. In a later episode, we will also look at how to create SwiftUI views ourselves that can be styled using this mechanism, so stay tuned!

From Issue 24  

FirebaseFirebase

Hacktoberfest 2023: Building a Car Maintenance app with Firebase and SwiftUI

Mikaela has been busy juggling writing code, doing live-streamed PR / code reviews, and getting to grips with being an open source product manager for her Hacktoberfest project.

If you're interested in working on an open source project that uses SwiftUI, Widgets, Firebase, and a bunch of other cool technologies in a beginner-friendly environment, head over to the repository for details on how to get started!

Or watch one of the live streams to get up to speed with what the team of 30+ contributors is currently working on.

From Issue 44  

SwiftSwift

Typestate - the new Design Pattern in Swift 5.9

In this article, Alex walks us through a real-world use case for the new non-copyable types in Swift 5.9. It contains a brilliant explanation of the Typestate design pattern, which brings the concept of State Machines into the type system, essentially preventing developers from writing illegal code at the compiler level.

State Machines play a critical role in many mission-critical systems, and Alex includes a bonus example that had me shake my head in disbelief.

From Issue 49  

SwiftUISwiftUI

Tutorial: Building Reusable SwiftUI Components

When I submitted my talk proposals to iOSDevUK, I also suggested my talk Building Reusable SwiftUI Components. It's a really good talk (I have been told) that walks through the process of refactoring a moderately complex List based UI into a reusable Avatar component that supports SwiftUI's styling API.

But the organisers, always on the look out to make iOSDevUK the best iOS/Swift conference, suggested running the talk as a workshop.

So I sat down and turned the talk into an interactive tutorial (using DocC). It's divided into four chapters that walk you through

  • Basic and more advanced techniques for composing views
  • How to make SwiftUI views customisable
  • Making your views interactive by adding action handlers
  • Using SwiftUI's styling API to make them stylable, just like the built-in views like Button or Toggle

You can finish the tutorial in under 2.5 hours, and I promise it will take your understanding of SwiftUI to the next level.

I've even been told that you do the entire tutorial just on an iPad using Swift Playgrounds, which is pretty mind blowing.

I hope you like the tutorial - if you finish, let me know what you thought about it. Or, even better, tweet about it, so other people can benefit, too.

From Issue #44  

Software Engineering

5 Tips to creating a (good) pull request

Writing a good pull request is an important skill, no matter if you're contributing to an open source project, a client project, or even an app for a hackathon.

Danijela has a couple of great suggestions for writing good pull requests.

The only thing I would add to Danijela's list is "remove any boilerplate template from the comment". Many open source projects (Firebase included) use pull request templates to make sure contributors provide the context that maintainers need to process the PR. Often, these templates include instructions how to use them. You should remove those instructions, as they're only intended to guide the PR author. Leaving them in will create a lot of noise for anyone reading the PR either online or in their email inbox.

From Issue 29  

AI and ML

Exploring Google AI SDK for Swift: Gemini AI Model for Text Only Input

I think this is the first article somebody wrote about the Gemini SDK for Swift. Great work by Rudrank , as always - I particularly liked to see how he forced the model into returning JSON so he could implement richer interactions on top of the the model output.

I've found that you can be even more specific. Here is a fragment of a much larger prompt I am using for a text adventure I am working on:

Provide the result in two blocks: the first block MUST ONLY contain the description, formatted as Markdown.

After the description, insert a newline, and a divider of exactly FIVE dashes (like this: "-----"), followed by the following JSON structure:

{
  description: String,
  health: Int,
  location: String,
  inventory: [String]
  commands: [String]
}

You can use Markdown for any of the strings in this JSON structure.

This allows me to use streaming for the first part of the response, resulting in a much faster response and better UX, while still being able to use the much richer output in the JSON structure.

From Issue 49  

Productivity

Xcode Tips

This is an excellent collection of tips and tricks for Xcode, put together by Toomas Vahter. Here are a few of my favourites:

  • Double-click a curly brace to select the block it surrounds (#39)
  • Open Xcode's command palette using Shift + Command + A (#36)
  • Simulate device conditions such as slow network or overheating device (#34)
  • Resetting SwiftUI previews when they hang (#29)
  • Use MARK, TODO, and FIXME keywords for structuring the jump bar (#14)
  • Show build time in Xcode toolbar (#3)
From Issue 47  

Writing

The visual reference guide for documenting your Swift code

Documenting is an important aspect of writing code, and thanks to DocC, it is easier than ever to create beautiful documentation from inline code comments and additional Markdown files.

Marco's guide for writing code documentation for Swift came in handy this week, as I was working on creating an interactive tutorial with DocC.

However, I noticed that some things work slightly differently for interactive tutorials. For example, callouts for tutorials have to start with >, whereas you can use - in source code docs.

This works fine for interactive tutorials:

> Warning: This will result in a compiler error.

This doesn't:

-  Warning: This will result in a compiler error.
From Issue 32  

Business

Bootstrapping a SaaS Business in Germany: How I did it

The first real app I built was a vocabulary trainer that I built using QuickBASIC 4.x when I was 16 years old. I distributed it as shareware, and sold the main app for the equivalent of 8 EUR per license.

Knowing nothing about taxes, licensing, or business in general at all, I had a hard time getting any traction, and eventually gave up.

I wish I'd had read Lukas' article back then (however, the internet didn't even exist yet) - it's got a lot of good advice for anyone who's considering bootstrapping a SaaS business in Germany. Definitely worth reading - even if you're not living in Germany.

From Issue 45  

Tools

Interface Builder for SwiftUI

Marcin shared a new feature in Judo: creating SwiftUI code from your designs in realtime.

This reminded a bit of PaintCode. While Judo seems to mostly target designers who are looking for an easier way to hand off their designs to developers, I seem to recall PaintCode was made for developers who were looking for a way to turn vector drawings into code.

I wonder if the Xcode might have an improved version of the SwiftUI preview canvas up their sleeves.

If you'd like to give Judo a try, there is a TestFlight link in this tweet.

From Issue 39  

Authentication

Skip typing your login credentials manually with Xcode breakpoints

Bringing an app into the initial state for testing a specific feature or reproducing a bug can be a tedious process, especially when having to go through a login process. Danijela discusses an interesting approach that makes use of Xcode breakpoints. Be aware though - this requires exposing the respective password in a breakpoint expression.

If you'd rather sign in without having to type in a password, consider implementing Anonymous Authentication, or use read Antoine's article about deep links in the SwiftUI section of this issue of the newsletter.

From Issue 39  

Security

Don’t ship API keys!

In issue #48, I discussed Thomas Vahter's article about using on-demand resources to keep your API keys safer, and also mentioned that to keep your API keys really safe, you should rather use a tool like App Check.

In this article, Thomas Durand suggest keeping your API keys safe by not shipping them at all.

I've been talking about using Cloud Functions as a trusted environment for a while now, and if you're interested in using this approach in your apps, I would encourage you to check out this Firebase Extension: Call PaLM API Securely - it demonstrates the approach Thomas (Durand) is talking about. You can clone the source code and apply it to your own code.

From Issue 40  

Web

Safari (for Mac) URL Scheme

Like many other apps, Safari has a couple of URL Schemes that come in handy at times. For example, when you want to make sure a specific URL is opened in Safari, no matter the user's default browser.

Christian also walks you through how to discover URL schemes in other apps.

From Issue 41  

Design

Hackreels - creating animated GIFs of your code

Now, if you'd rather not spend a lot of time creating beautifully animated GIFs of your code using Keynote, Hackreels might be just the tool for you.

It supports bunch of languages and frameworks (albeit a bit web-focused), and is capable of creating transparent videos.

There is some room for improvement, though: you might notice that some characters are randomly flying around between the different stages of the animations, which is something that you can avoid in Keynote. But - it's a great start, and I expect they will fix those issues in subsequent releases.

From Issue 46  

Conferences

Conferences? There is an app for that!

How do you track conferences and ideas for talks? I’ve been using a couple of approaches (wikis, internal databases and spreadsheets, and - most recently - a combination of Asana and Craft) in the past, but Oliver is going all in and started building an app.

Also - I need to look up all those other conferences!

From Issue 24  

Podcasts

The Apollo Guidance Computer 1202 Alarm

If you've listened to the 13 Minutes to the Moon podcast, you might know what the infamous 1202 alarm of the Apollo Guidance Computer is about.

But no matter if you do or if you don't, I would encourage you to watch this amazing talk by Robert Wills: Light Years Ahead. It is not just about the Apollo Guidance Computer and the nerve-racking final couple of seconds before the landing on the moon - it's also a tale about software engineering, and how the six design principles employed by the team around Margaret Hamilton) to make sure the computer wouldn't fail the mission:

  1. Use a high-level language
  2. Divide your system into jobs
  3. Restart on failure
  4. Checkpoint good state
  5. Hardware monitors the software
  6. Send telemetry

BTW - the source code for the ACG is available on GitHub.

From Issue 44  

Computer History

Q: Setting User-Agent Field?

Before we had StackOverflow, people used to ask questions on the Usenet. Here is a question by one Lawrence Page, who you might better know as Larry Page, one of the co-founders of Google, about the User-Agent field of Java. One of the earliest public signs of what later became Google (see this Wikipedia reference for more details).

From Issue 41  

Fun stuff

SwiftXP

😱

From Issue 28