Firebase
Fewer cold starts, more features in Cloud Functions
Did you ever need to set up a server to run some backend code? Cloud Functions for Firebase are a great way to build backend functionality without having to set up, manage, and maintain your own server.
In this blog post, Dmitry Lyalin and Jeff Huleatt walk through some of the new features of Cloud Functions for Firebase v2, such as
- Fewer cold stars
- Faster deploys
- Parameterized configurations
What's great about Cloud Functions for Firebase - you can call them from your mobile app, and the call will include information about the authenticated user. Here is a code snippet that show how to call a HTTP Callable Cloud Function from a Swift app:
import FirebaseFunctions
func callFunction(numer1: Int, number2: Int) {
// Create a reference to the Cloud Functions service
let addNumbers = Functions.functions().httpsCallable("addnumbers")
Task {
do {
// Call the function and pass in the data you want to pass as a dictionary
let result = try await addNumbers.call(["firstNumber": number1, "secondNumber": number2])
// Parse the result and print it
if let data = result.data as? [String: Any], let operationResult = data["operationResult"] as? Int {
print("The result is \(operationResult)")
}
}
catch {
print(error)
}
}
}
Swift
Moving "The Swift Programming Language" book to open source
The Swift Programming Language book is now an open source project.
The current version of the book published on Swift.org is still based on Apple's internal toolchain, but one of the goals of the open source project is to use DocC to generate future versions of the book.
The team is looking for feedback about any issues you might run into when compiling, editing, or reading the book.
This is a great move by the Swift team, and it reminds of Tech Lead Journal episode #29 - A Guide to Technical Writing and Content Creation with Helen Jo Scott, in which she recommends crowdsourcing your documentation, or making it editable by your users.
SwiftUI
Making entire List rows tappable
The default behaviour in a SwiftUI List
view is to only make the list row's content (i.e., the text, icon, etc.) tappable. Here is a nice trick from Daniel Saidi to make the entire row tappable.
A list of all of SwiftUI’s environment and preference keys
In my opinion, the environment is one of the most underrated aspects of SwiftUI. In fact, it is what makes many of SwiftUI's view modifiers even possible (as discussed in this video).
Robb Böhnke has put together an overview of all known EnvironmentKey
s, LayoutValueKey
s, PreferenceKey
s, and ViewTraitKey
s.
BTW - in case you didn't know: GitHub supports tables!
Productivity
Predefined SwiftUI code snippets in Xcode
I knew Xcode supports code snippets, but I never took the time to explore them properly. Thankfully Marco Eidinger did, and discovered a bunch of useful snippets for SwiftUI.
The cool thing about code snippets is that - unlike keyboard shortcuts - you don't have to memorise them. You can either open the Xcode Library (using ⇧⌘L) to see a list of all the available snippets, or start typing the name in Xcode's code editor.
Literal expressions for logging
Print debugging might seem like an arcane art, but at times, it can be really useful. @StewartLynch with some useful literal expressions that work both in print()
debugging and when using a real logging API.
Auto-indent code in Xcode
Xcode added auto-indentation when typing a closing }
in one of the recent versions. Most of use will have discovered this when adding a chunk of code and then typing the closing }
.
A feature that is less discoverable is selecting a block of code and typing an opening {
- this will wrap the code in curly braces and indent it. Really useful for SwiftUI.
Ed Sánchez recorded a video that shows this in action
StackOverflow
Firebase Authentication - Sign In with Apple: nonce returns nil
In this question, the OP describes a situation in which the nonce
used in the Sign in with Apple flow is nil
when the user has completed the sign in flow and the callback for completing the authorisation request is called.
It turns out the issue was a small, but significant typo, resulting in the view model being re-created every time the SiwA button called one of the completion handlers.
I guess we can learn two things from this: 1. Pay close attention when making changes to code you copy and paste from sample code. 2. It might be worth making sample code more resilient to potential typos.
Conferences
CfP: Deep Dish Swift 2023
Deep Dish Swift is a brand new conference being held in Chicago from April 30th to May 2nd in 2023, organised by none other than Josh “🍕 conf” Holtz. If you love pizza, Swift, Chicago, or all of the above, consider submitting a talk via PaperCall!
CfP: NYSwifty 2023
NYSwifty is a brand new Swift Conference in New York City, taking place in April 2023. The web site is slowly taking shape. If you're interested in speaking, their CfP is open at PaperCall, and will close on December 31st, 2022.
Fun stuff
Where did the command ⌘ symbol come from?
Have you ever wondered what the command (⌘) symbol means and where it comes from? Watch this wonderful presentation by Susan Kare, the iconographer of the early Macintosh icons, in which she talks about this and more.
Comment
👋🏻 Hi everyone!
The end is near... The end of the year, that is! I don't know about you, but time has been flying for me.
Just last week, I spent some time in London to record a bunch of videos in our studio - mostly for our Firebase Fundamentals series, but we also tried something new (which had me throwing my phone across the set)
One of the videos is about using Firebase Anonymous Auth and Account Linking to implement a smooth onboarding experience for your users. I will write about this in more detail in the next issue.
In other news, we've released an updated preview version of Cloud Functions for Firebase with a bunch of really amazing features (fewer coldstarts!) - read more about it in this issue.
To help us all be a bit more productive, I've linked to a couple of Xcode productivity tips & tricks you might not yet know about!
As always, I love hearing from you. You can get in touch with my by hitting the reply button in your email app, or send me a DM on Twitter (I am @peterfriese) or on Mastodon (I am @peterfriese@iosdev.space).
Thanks for reading, I look forward to hearing from you!
Peter
PS: In case you're wondering - I've moved this newsletter from Revue to Curated.