What I am working on
I talked to ChatGPT for 1.5hrs and all I got was a lousy todo list app - YouTube
I had a long conversation with ChatGPT (2hrs in total, but I edited it down to 1.5hrs) - I wanted to see if it can build a todo list application using Swift and Firebase. Specifically, I wanted it to use Cloud Firestore to store the todo items.
It went quite well in the beginning, but when we got to talk about Firebase, things went south pretty quickly. But see for yourself.
Firebase
Burn after reading 🔥
Cloud Firestore now supports a count
function that you can use to determine the number of documents in a collection or a query - this is something a lot of people have been asking us for.
Here is a Swift snippet that shows how to fetch the number of all documents in the posts
collection:
func countALlPosts() async throws -> Int {
let countQuery = db.collection(Post.collectionPath).count
let snapshot = try await countQuery.getAggregation(source: .server)
return snapshot.count.intValue
}
We've also lifted some of the limits, such as
- Maximum reads per second
- Maximum writes per second
- Maximum concurrent, real-time, connections
Oh, and if you ever need your documents to expire after a certain period of time (e.g. for compliance reasons), Firestore now also support TTL policies. 🔥
Build an Android app with Jetpack Compose and Firebase
Someone recently told me "I really enjoyed learning Swift and SwiftUI - the concepts are very similar to Kotlin and Jetpack Compose". If you want to find out if this is true in the opposite direction, here is your chance!
In this learning pathway, you will learn how to build an Android app that follows the Model-View-ViewModel (MVVM) architecture and prepare a codebase to use different environments with Jetpack Compose and Firebase.
Swift
Five Things You Didn't Know About KeyPaths in Swift
Vincent dives into Keypaths and shows some lesser known features and how you can use them to make your code more type-safe.
Swift.org - The Future of Foundation
Apple announced that they are going to open source Foundation, written entirely in Swift, for Swift.
This is a big deal, as it means a couple of things:
- There will be a 1:1 parity between all supported platforms.
- All code will be written in Swift, no more wrapped C code. This will make debugging so much easier - no more black box when your code calls into Foundation.
- There will be an open contribution process. Found a bug? You can now fix it! Have a feature request? You can now write a PR and chances are it might actually be included.
It's pretty exciting to see Apple announce the Future of Foundation at the Servers-Side Swift Conference, and I am curious if they will eventually open source SwiftUI as well.
SwiftUI
Where View.task gets its main-actor isolation from – Ole Begemann
When using the .task
modifier inside a helper property or a function inside your View
, you might have run into a compiler error telling you that your code is 'async', but is not marked with 'await'.
The reason for this error is how the .task
view modifier gets is main-actor isolation. Ole goes behind the scenes to explain how this works, and what you should do to prevent this.
Definitely worth a read if your refactoring larger SwiftUI views into smaller pieces.
Scrolling to the top of view when tapping a tab
Scrolling to the top of a List
view (or any other scroll view) when tapping a TabView
is such a common UI pattern on iOS that I always find it surprising this isn't part of the platform. Mahesh Sai shows how to implement this with a few lines of code.
Turn-key animations for your iOS apps
This library has some amazing effects - check out the interactive demo.
AI and ML
Can ChatGPT Make This Podcast? - Hard Fork
Casey Newton and Kevin Roose discuss what ChatGPT is, its capabilities and limits, why everyone is so excited about it, and if it will replace our jobs (aren't all conversations about new technology about whether our jobs will be replaced?).
In the second part of the conversation, they chat with Aviv Ovadya about ways to use AI and ML democratically. Should this kind of technology be regulated? And where do you draw the boundary?
How ChatGPT Changes Tech + The End of Remote Work? — With Aaron Levie - Big Technology Podcast
One of the most interesting parts of this conversation between Alex Kantrowitz and Aaron Levie (CEO of Box) was the moment when they discussed why ChatGPT's corpus ends in 2021. Is it because OpenAI didn't want to get too close to Google's search business, or rather because ChatGPT has this tendency to be very confident about what it says - even if it's objectively wrong.
A GPT-based assistant that has access to your browser tabs
I love the idea of having an assistant that can answer questions for me based on a knowledge base I curated. This would be super helpful for answering questions on StackOverflow. But then again, StackOverflow banned the use of ChatGPT. Oh well.
Prototyping SwiftUI interfaces with OpenAI's ChatGPT
Moritz takes ChatGPT through the paces, starting with a simple prompt ("create a SwiftUI app that shows a list of all heart emojis and the name of the emojis") to a more complex one: "create a to do list app with swiftui". It's interesting to note that the second prompt reads a lot simpler, but yields a much more impressive result.
Productivity
Xcode's refactoring options for async/await
If your codebase is still mostly using completion handlers and callbacks, you might want to migrate to using async
/await
.
Xcode has a bunch of refactorings that can help make this process easier. In this blog bost, Marco Eidinger walks you through them, and provides examples for how they work.
BTW, did you know all those refactorings are part of the Swift Open Source Project?
Tools
AppCode 2022.3 Release and End of Sales and Support | The AppCode Blog
AppCode was a lot more mature than Xcode in many regards (most prominently refactoring), but the JetBrains team has had to play catch-up ever since they released AppCode for the first time in 2011. With not enough adoption, it’s understandable they need to focus their time and efforts on other, more sustainable endeavours.
It's really a weird experience to read their release notes blog post with all those amazing new features and improvements they packed into the last release:
- Better Swift refactoring capabilities
- Enhanced completion for initializers and deinitializers
- Intention previews
- Injected languages
- Updates to UML diagrams
- Settings synchronization
It's a bit like your favourite band going on tour with an amazing new album and then telling everyone "we're breaking up - after the tour".
Let’s hope Apple continues improving Xcode to fill the glaring gaps. Oh, and wouldn’t it be nice to have a proper plug-in system?
Freeform - Apple's new app for creative collaboration
Announced at WWDC 2022 in June, Freeform is Apple's new collaborative whiteboard app that works across the Mac, iPad, and iPhone. The reviews so far have been really positive. If you want to get a quick overview of how it works, check out this short video
Coduo – Share and collaborate in Xcode
I've used the beta version of Coduo, and it's a pretty magical experience. Coduo allows you to stream your Xocde window (and Simulators) to one other person via peer-to-peer networking.
The other person can draw on the screen to ... draw your attention to certain areas of the code. They can also take control of the mouse and keyboard, which makes Coduo a great tool for pair-programming, mentoring, or if you're stumped and just need to ask a co-worker to take a quick look at your code.
The website is missing a pricing chart, but the Mac App Store listing shows that an upgrade to Coduo Pro (for streaming your entire screen, and an auto-follow feature) is $14.99, which is a steal, if you ask me.
Comment
The past two weeks have been wild - it seems like everybody is having a lot of fun with ChatGPT.
People have used it to write poems, songs, essays - and even software.
I've been playing around with ChatGPT, and while I was blown away initially, I quickly noticed its limits.
It's not a secret that ChatGPT is not very good at math, and - especially when it's wrong - it sounds overly confident (maybe to make up for a lack of knowledge?).
When I asked it build a todo-list application with SwiftUI and Firebase, it did quite well in the beginning, but didn't do too well when it had to write code for persisting todos in Cloud Firestore. In particular, it was very hard to convince it to use
Codable
instead of mapping Firestore documents manually. You might argue that its corpus only includes knowledge up to 2021, but Firestore has supported Codable since 2019, and even my article about mapping documents is from early 2021.Don't get me wrong - giving more or less plain-language instructions to a computer and receiving meaningful (and often high-quality) output within seconds is pretty impressive.
Will it change our jobs? Yes, it will. Just like the invention of the assembler, the compiler, and other tools did. I see it as a productivity tool: great for brainstorming ideas and exploring a topic. Fantastic for summarising texts, and good for pointing you at potential issues with your code (be careful when feeding it code that might be owned by the company you work for!). Not entirely rubbish for writing code, although it made some spectacular blunders in some of my experiments.
But it's not going to replace software engineers, lawyers, journalists, scientists, or any other job. It's a tool, and a pretty powerful at that. It will make us more efficient - if we use it right. And it will also require us to be more alert - going forward, it will be difficult to say if a piece of text of code has been written by a human or a machine. And we should spend more time thinking about the moral implications of AI/ML technology. Software ethics no longer is an issue that can or should be discussed in the ivory tower - it is on us to set ourselves boundaries / decide if the use of a large natural language model is appropriate / acceptable for a specific use case or not. And - sooner rather than later, we need to discuss the moral implications as an industry and civilisation.
Thanks for reading
Peter 🔥