Digest: iPhone 15, Dependabot & SwiftUI Cookbook

Article's main picture
  • #iPhone 15
  • #Xcode
  • #Swift

• 6 min read

Welcome to the @mainNews Digest! In today’s edition, we talk about supercharging your project build times in Xcode, getting rid of memory leaks in XCTest, added Swift support for Dependabot, a fundamental book on SwiftUI, and the upcoming iPhone 15.  So much to uncover so let’s get started!

iPhone 15

September's almost here, and we all know what that means: Apple is about to unveil iPhone 15!

What do we know so far? Well, perhaps the most interesting change is Apple ditching the iconic ringer mute switch on the side for either a mechanical or haptic multi-functional button.

Ring/Silent Switch. Image: Apple Inc.
Ring/Silent Switch. Image: Apple Inc.

The replacement most likely comes in the form of the Action Button from Apple Watch. Users can customize it to perform various things, such as open the Camera app or turn on flash. It will also be possible to add any action in the Shortcuts app. Most likely, the new iPhones will have a USB-C port instead of Lightning granting higher charging speeds.

The Dynamic Island will ship with all models. And as for the iPhone 15 Pro, expect smaller bezels and a more rounded design.

And of course, the camera and processor will get a little better, but most people won’t even notice the difference.

Swift support for Dependabot

Great news! Dependabot now comes to Swift.

For those unfamiliar, Dependabot is a bot that scans the third-party dependencies in your project. If these dependencies have updates with security fixes, the bot will create a pull request for you. So, you don't have to manually look for critical updates.

Dependabot started out as an external service, but since 2019 it has been integrated into  GitHub. Now feel free to use it with Swift! We also have a comprehensive article on using Dependabot on our blog.

Build performance analysis for speeding up Xcode builds

Now, let’s move on to the topic that is relevant to everyone: slow build times. I bet many of you wish to make the process quicker.

Method 1: Report Build Timeline

Good news is Xcode actually provides a tool to analyze how much time each stage takes. But it’s a bit tricky to find. So here's how to find the tool in Xcode:

Head over to the “Report Navigator” tab and select the build you want to examine

Next, find the button with the little lines (it's in the top right) and click Assistant.

Ta-da! You'll see the whole timeline showing what got compiled and how long it took. Now, you can get to work optimizing things.

Method 2: Build With Timing Summary

There’s also another way to view the statistics. Try the 'build with timing summary' option in the product menu up top.

It gives an overview of how long certain processes took – be it compiling, signing, or external scripts.

And speaking of scripts, you have to be strategic about them. Take SwiftLint, for example. It can be slow because, by default, it lints not just the differences, but all the code. That's why we are now using the swift-format with auto-formatting and added it as a pre-commit hook.

Important disclosure: these tools won’t magically solve all your issues. If your codebase is huge, your project will still take time to build. BUT… you can reorganize dependencies or spot the non-obvious parts that take ages to compile.

How to automate memory leak detection in your Swift code with XCTest

I also want to share with you a neat solution to finally get rid of memory leaks. And yes, it involves tests.

addTeardownBlock function. Image: Apple Inc.
addTeardownBlock function. Image: Apple Inc.

In XCTest, there's this function addTeardownBlock, which is called right after a test completes. Basically, at a moment when all objects should be cleared from memory. This is precisely where you can capture a weak reference to the object and check whether it was deleted.

With a bit of playing, you can create a function trackForMemoryLeak. Inside it, you'll have a block with an assertion and a clear error description.

I've added this to my projects as a go-to solution for memory leaks.

SwiftUI Cookbook

More good news for the Swift community!

Kodeco, previously known as raywenderlich.com, has released a free book on SwiftUI titled SwiftUI Cookbook.

SwiftUI Cookbook. Image: Kodeco Inc.
SwiftUI Cookbook. Image: Kodeco Inc.

It's packed with 22 chapters! So, we're not just talking about a few lessons on crafting a view. This book is a foundation that covers all the UI elements, animations, observing, localization, and architecture.

It's packed with 22 chapters! So, we're not just talking about a few lessons on crafting a view. This book is a foundation that covers all the UI elements, animations, observing, localization, and architecture.

It's an absolute goldmine if you're just starting out with SwiftUI.

Make sure to subscribe to our blog to get the freshest news from the world of iOS and macOS development. Don't forget to subscribe to our newsletter to stay in the loop. You can also find engineering and design updates, in case you're not solely into iOS.

Resources

Swift Support for Dependabot

addTeardownBlock

SwiftUI Cookbook


This is an independent publication and it has not been authorized, sponsored, or otherwise approved by Apple Inc. and Kodeco Inc.

More From engineering

Subscribe to our newsletter