Not Only Swift

By Peter Friese

🔑Better Safe than Sorry - Not Only Swift Weekly - Issue #14





Subscribe to our newsletter

By subscribing, you agree with Revue’s Terms of Service and Privacy Policy and understand that Not Only Swift will receive your email address.

Peter Friese
Peter Friese
👋🏻 Hi everyone!
I had the opportunity to attend Apple’s A conversation with SwiftUI Engineering session this week (at an EMEA-friendly time!), and took away some new insights. The session had two lightning talks about What’s new in SwiftUI since the last beta and What happens when you file feedback. The majority of the session was reserved for Q&A, with the SwiftUI team taking live questions that attendees could ask via the text chat.
For me, the most helpful part was the Q&A session, partly because the team provided some great answers to the audience’s questions, but also because it was a great opportunity to sneak in a couple of feature requests and process improvements thinly disguised as questions.
The presentation about how Apple’s Feedback system works didn’t reveal any groundbreaking new insights, but it was helpful to see that your feedback is indeed routed to the respective teams (sometimes in aggregate form), and is being read by the team members. My only suggestion for Apple would be to add a flag to indicate that a Feedback has been read / seen by someone. This way it’d feel less like a black hole ;-)
BTW, one of my questions was, “are there any plans to open source SwiftUI?” (given Swift itself is open source, and the process seems to be beneficial both for Apple and the community). Needless to say, this question wasn’t answered. But I am pretty sure the team saw it :-)
As always, I love to hear your feedback for this newsletter! Do you like the links I curate? If yes, click them - this makes me happy, and helps me curate content for next week’s issue. You can also reply to this email and tell me what you think, or just to say “Hi!”.
Thanks for reading,
Peter 🔥

What I am working on
I took some time this week to implement some additional fields on the details dialog for Make It So - in particular, the date and time fields. Displaying date / time pickers inside a SwiftUI Form isn’t that complicated at all, and once I figured out how to keep track of whether or not the user cares about the time of the due date as well, managing the data model and view model was pretty straight forward (I ended up keeping almost all date handling inside the view model(s), as any special handling pertains to the UI).
However, I wanted to also implement the accordion-style UI that allows users to show / hide the pickers when they’re no longer needed. Again, no big deal in terms of implementation, thanks to SwiftUI. However, there is some visual jank I wasn’t able to get rid of that is rather prominent when hiding the date picker - no idea why it transitions out to the bottom of the screen… Check out this video which show the effect with slow animations turned on:
Janky animations when showing / hiding date pickers
Janky animations when showing / hiding date pickers
As always, the code is available on this GitHub repo (make sure you use the develop branch) - feel free to clone it and take it for a spin!
🔥 Firebase
If you’ve noticed that user have been logged out from your app, this might be caused by an iOS 15 feature called pre-warming. As Liam Nichols states in his article
Starting with iOS 15, the system might decide to “pre-warm” your app before the user actually tries to open it and this can increase the chances of protected data not being available when you think it should be.
Apps using Firebase Authentication might suffer from this behaviour as well - see issue #8695: Firebase Auth - Signing users out after 30 minutes (As of Xcode 13, iOS 15 SDK). The good news is that we now have a better understanding of where to look. Reproducing this behaviour obviously isn’t easy, as Liam explains in his article, so it might take a while for a fix to land.
On a related note, we’ve just published the first episode for a new series of videos about Firebase Authentication and how to build safe and secure applications using Firebase. Join Rachel and me as we explain the differences between authentication and authorization, why it is safe to directly access your database from the client (#securityrules!), and how to protect your backend resources. We’ve got a long list of topics to cover in the series, so definitely make sure to subscribe. Oh, and if you have any suggestions for topics you’d like to see us cover, drop us a comment, or reply to this email!
What is Firebase Authentication? | Better Safe than Sorry
What is Firebase Authentication? | Better Safe than Sorry
When rendering views, SwiftUI usually uses a rectangle to place them inside the container view. This can become an issue when implementing tap gestures. Other times, you might want to use a non-rectangular shape for a view’s content, for example when implementing drag and drop.
I recently ran into this issue myself when implementing an accordion effect for the details dialog in Make It So.
Majid walks us through the contentShape() view modifier and how it can help: Customizing view content shape in SwiftUI
It’s this time of year again, and many of you might be taking part in the 2021 Advent of Code. A lot of the puzzles can be solved using well-known algorithms. Apple recently released Swift Algorithms, a package full of algorithms (mostly for sequences and collections), optimised for performance and flexibility. Here is Paul Hudson with an overview of some of the algorithms and some practical applications.
Write better code with Swift Algorithms – Hacking with Swift
On the note of Advent of Code, @jordanranson announced that he decided to implement everything in Lua and post visualisations for each day. Quite a commitment!
The visualisation for day one (The Elves Submarine) looks really neat, and I can’t wait to see what he comes up with for all the other days!
Tools and Libraries
Adam Fowler has posted a couple tweets about building servers using Swift this week. He started with how to write a web server in less than 30 lines of code (gist), then wrote about building a HTTP proxy server with Swift, and rounded the week off by turning his web server gist into an installable package. If you’ve got mint installed, you can install swift-web using mint install adam-fowler/swift-web. To serve files from a local folder, just run swift web in the respective folder. You currently doesn’t seem to retrieve index.html by default if you just provide a path, but that’s probably an easy fix. Definitely an alternative to running python -m http.sever, especially for tools that are written in Swift (like John Sundell’s Publish)!
I’ve started to learn touch typing earlier this year, and one of the things I find really cumbersome, especially when coding, is that you have to move your right hand to a different position for moving around using the cursor keys. 
Maybe using Emacs keybindings (as mentioned by @shahidkamal) is more efficient? At least it’s worth trying:
Shahid Kamal Ahmad
You old Mac hands know this, but this is for those who touch type on their Mac and want home position shortcuts to common editing operations. You’ll rarely need to use cursor keys after this. I certainly don’t.

Ctrl = ⌃
Option = ⌥

1/5 👇🏽
And finally…
Did you enjoy this issue? Yes No
Peter Friese
Peter Friese @peterfriese

Xcode tips & tricks, Swift, SwiftUI, Combine, Firebase, computing and internet history, and - of course - some fun stuff.

In order to unsubscribe, click here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Created with Revue by Twitter.