Give your simulator superpowers

Give your Xcode
Simulator extra features

Issue 126
Aug 02, 2022

Refactoring feels like a step back.

Last Sunday, I hung out with some Indie Developers you might know, and I had a chat with Hidde about some of the code he showed me. Hidde asked me about a centralized file in his project that contained much of his logic.

We quickly started discussing refactoring and the fact that a refactor can often feel like a step back. You could have used that valuable time to develop new features instead, isn't it?

In the same discussion, we mentioned tests. I'm pretty sure you'll have fewer large files if you write tests often simply because it's harder to write tests for large files. There's no overview, and it's hard to find out what you need to test.

While it's hard to measure the gains of a refactor, I'm pretty sure there are many cases in which you'll benefit from readable and testable code. Especially in SwiftUI, having one large file that is also used as an ObservableObject can easily lead to unexpected behavior and unneeded redraws of your views: simply because many views will depend on the many responsibilities of the main file.

If you're asking yourself the question now about how to find out whether you need a refactor, I will encourage you to look at your code and find out whether you've been using many // MARK statements or filenames like "DataController+Content" or "DataController+Images." Both indicate where you could introduce single responsibility, like "ContentStore" and "ImageFetcher."

Refactoring can be a great way to gain new insights. Increase productivity, and simplify testing. Yes, it costs time, but will it cost more than it saves you? Who knows!

Enjoy this week's SwiftLee Weekly!

THIS WEEK'S BLOG POST

While I wrote about Sendable before, I did not cover enabling the new strict concurrency checking build setting in Xcode 14. This new build setting allows you to prepare for Swift 6, in which new warnings will be triggered for instances used as Sendable while they're not thread-safe. For both WeTransfer and Stock Analyzer, I'm currently working on fixing related warnings, for which I decided to dive into solving the most commonly triggered issues.

SPONSORED

Although you can create an app simply by throwing some code together, without best practices and a robust architecture, you’ll soon end up with unmanageable spaghetti code. Learn how to create solid and maintainable apps with fewer bugs using this free guide.

SWIFTLEE JOBS

Get your job positions listed on all 190+ SwiftLee articles and 4 SwiftLee Weekly editions. Read more.
Browse Swift-related Jobs, or add your own on SwiftLee Jobs.

CURATED FROM THE COMMUNITY

SWIFTUI

I watched the Lock Screen widget WWDC session last week, demonstrating this view. Majid Jabrayilov’s article is short and to the point, but I believe it’s a crucial SwiftUI view to be aware of, so no excuses for not quickly reading this!
While I can’t think of a scenario yet in which I would need this in my apps, I do see value for this with apps like games or full-screen experiences. Daniel Saidi explains how you can hide persistent system overlays in SwiftUI without resorting to UIKit hacks.
Through this mention, I want to thank Keith Harrison for showing me Gauges! I did know they exist, but I only just realized I can use them for Stock Analyzer now.

SWIFT

While I wish this article showed some more code examples on how to implement this for real, I do want to point out that Will Bishop shares a crucial detail when working with the pasteboard in iOS. If you can use the pasteboard without showing the user an alert, you can improve the user experience significantly.
Nil Coalescing shows how combining Swift Charts with Foundation’s Measurement type results in a beautiful output from readable code.
Large numbers can be hard to read: 1000000. Is this 1 million or 10 million? I bet it’s easier for you to say when I type 1_000_000. Sarun W. explains how you can benefit from this technique in Swift.
Marco Eidinger ‍shares tips for Swift Package Plugin development based on hands-on experience. If you plan to work with plugins, you’ll likely benefit from reading these tips.

APP STORE OPTIMIZATION

As you might remember, I’ve had a live session together with Ariel From Appfigures to share with you my knowledge regarding outranking competitors by growing your App Store Ratings. We’ve managed to get 12K ratings in just three months with the WeTransfer application by applying a specific technique that I explain in detail.

BLOGGING

Last week I discussed with Wouter Dijks and convinced him to start writing on his blog. He took my advice seriously, and I want to prove that his first article can be valuable for anyone already! Wouter has just started his journey of Swift development and shares his approach to learning Swift. While it might not work for you ultimately, you might benefit from the tools he uses to create structured planning.

APPS

You might know Jordi Bruin from several other apps he developed, but this time I’m thrilled to share his app since my App Store Connect SDK fully backs it! The app simplified managing App Store customer reviews with features like reply templates and translated responses.