Swift
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.
Trigger property observers from initializers in Swift
If you're like me, you run into this situation all of the time: you need to perform some initialisation work, but the object isn't fully initialised yet.
In this article, Natalia discusses a couple of strategies to work around this situation. I've got a feeling I will come back to this article a lot.
SwiftUI
How to Inspect SwiftUI.TextField.onSubmit and Figure Out You Can't Programmatically Use It
I recently worked on implementing a SwiftUI text input view for a chat application, and found myself wondering if it's possible to re-use the onSubmit
event handler.
It turns out that this isn't possible - but don't take my word, read Christian's article instead - he really digs into the details.
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.
Productivity
Xcode Keyboard Shortcuts
As developers, we spend a ton of time in our IDEs, and learning some keyboard shortcuts is key to being more efficient.
Here is a great collection of Xcode Keyboard Shortcuts. I love how Keith decodes the jump bar - now it finally makes sense why Document Items (or Document Outline, as I like to think of it) is ^6
- the items on the jump bar are enumerated 🤯
Tools
Follow Swift news using news.digitalbunker.dev
I mostly use Twitter (yes, I still call it Twitter) and Marco Eidinger's excellent iOSDevUpdates site to stay on top of what's new in the iOS / Swift ecosystem.
iOS Development News by Aryaman Sharda is a welcome addition for anyone wanting to stay in the loop - it features a beautiful UI, organising news into development blogs, company blogs, marketing and business blogs, and YouTube videos. In the side bar, it shows a list of new and updated Swift packages. Everything you need in one place - really nice.
Of course, both iOSDevUpdates and iOS Development News are based on Dave's iOS Dev Directory, so don’t forget to add your own blog or YouTube channel to make sure to get it in front of more readers.
Security
Don’t ship API keys! — Dean’s blog
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.
Computer History
From 486 to Vue.js: Evan You's Full-Time Gamble on Open Source
In this interview, Adam Gordon Bell talks with Evan You, creator of Vue.js, about his journey into full-time open source.
I’m not a web developer, but I found it very inspiring to hear how Evan found success by pursuing his dream. The episode also provides some really good insights into how much work and emotional labour goes into maintaining open source projects.
Next time you feel like ranting about a project, stop and think how the creators might perceive your words. Evan talks about the disproportion of negative vs positive feedback online and the opposite ratio offline. So - if you’re using a tool that you like: tell the creators - it will make their day, I promise.
Comment
These past have been super busy for me - mostly with getting all the developer materials for Gemini SDK for Swift in place. Gemini is Google's largest and most capable AI model yet.
One of its key capabilities is reasoning about multi-modal input: for example, you can pass in the confused Travolta meme and ask it what happens in the scene, who's the actor, and why their character is confused in this scene.
After the launch, I've been playing around with the SDK a lot more, and started building an LLM-powered text adventure for one of my favourite books. Can't wait to share more with you!
I hope y'all get a chance to wind down and celebrate some of the achievements you accomplished this year. I, for one, look forward to spending some time with my family, enjoying good food, playing some games, and digging into that giant pile of books that has accumulated over the past couple of months...!
Thanks for being a subscriber!
Peter Friese