3 min read

Issue #61

Hi there, welcome to the 61st issue of iOS Code Review! Here's to another round of curated learnings ☺️ This is the last issue of 2023 - I wish you happy holidays, and see you in January ☃️

What if you could instantly resolve a critical issue in prod, with a single click? Rollbacks by Runway allows you to do just that.

Runway automatically re-signs your previous live production build and preps it for a possible rollback release — including preemptive submission for review — to remove all sources of stress and delay. Runway is the first platform to enable rollbacks for native mobile apps.

Try Runway for free

UIViewController viewIsAppearing

Unlike viewWillAppear, by the time viewIsAppearing is called, the view has been added to the view hierarchy, has accurate geometry, including size and safe area insets. Available from iOS 13!
Using this method, it's a breeze to add animations to the content of the view controller that have to execute when the view first gets shown.

From viewWillAppear to viewIsAppearing - Perfecting Your iOS View Transitions
In WWDC23, Apple introduced a nuanced addition to the UIViewController lifecycle: viewIsAppearing. This instance method is a game-changer for developers looking to fine-tune the presentation and layout of their views. Let’s explore how this method enhances the way we build responsive and dynamic interfaces.

Catching memory leaks on CI

It's annoying how easy it is to accidentally introduce memory leaks into our code. Just a little self sneaking into a closure past a code review, or an omitted self causing troubles when passing a method in place of a closure. We can add checks to unit tests verifying certain objects get deallocated, but it's not nearly possible to catch everything. We can use the leaks instrument (included with Xcode) to see if the app has any memory leaks at any given moment.

Here's a brilliant approach to automating catching leaks on CI:
1. Use a UI testing framework to simulate the flow in the application
2. Use the leaks tool provided by Apple to generate a memgraph.
3. Write a script to process the generated memgraph to check for leaks. If there any leaks are found, use Danger to mark the PR as failed or post a message to Slack.

Automating Memory Leak Detection with CI Integration for iOS
A solution to automate memory leak detection in iOS Development

Opening SFSafariViewController, cleanly

In SwiftUI, we can utilize .openURL environment variable to catch any element trying to open a link, and, for example, open it in an embedded browser instead. Moving that logic into a view modifier, the usage site becomes so clean 🤩 Check out Antoine's article for the full code.

struct SwiftUILinksView: View {
    var body: some View {
        VStack(spacing: 20) {
            /// Creating a link using the `Link` View:
            Link("SwiftUI Link Example", destination: URL(string: "https://www.rocketsim.app")!)

            /// Creating a link using markdown:
            Text("Markdown link example: [RocketSim](https://www.rocketsim.app)")
        }
            /// This catches any outgoing URLs.
            .handleOpenURLInApp()
    }
}
SFSafariViewController in SwiftUI: Open webpages in-app
Use SFSafariViewController in SwiftUI and catch any outgoing URLs to ensure they open in-app instead of in the external Safari browser.

Ultimate SwiftData guide

For anyone looking for a clear roadmap for the journey of learning SwiftData, this is it. One of the longest articles I've ever seen, but you don't need to jump around a ton of different articles and WWDC videos. Although, I always recommend reading official documentation and watching official videos.

The Ultimate Swift Data Guide
The Ultimate Guide to Building SwiftData Applications

✌️
Alright, that's it for today! Let's spread the good code vibes ✨🧘🌈☀️
Thank you to Runway for sponsoring this issue ❤️
I'm curious if you found any of the tips particularly interesting - let me know by replying to this email!