Tony Ngo2 min

Swiftly Highlights: Holiday Cleanup & a Dash of Refactoring

EngineeringDec 6, 2022

Engineering

/

Dec 6, 2022

Tony NgoiOS Engineer

Share this article

Before indulging in November's Swiftly Highlights, don’t forget about the ongoing Ask Apple series that has just finished its first two rounds. Don’t quite know what to ask? Well…

… you can get inspired by this Q&A: 10 Questions with Design Evangelism, which is full of highlights of the Apple design team's conversation around design philosophy, guidelines, tips, guidance about HIG and much more.

Now, let’s get to the November edition of the latest and greatest articles, hand-picked by our engineers.

With deadlines loosening up, the holiday season upon us and the year coming to an end, it just might be the perfect time to give those "we will refactor when there’s time" tasks some attention.

Unit Test Best Practices

When cleaning up and refactoring code, it is vital to be backed up by good unit tests. So, before doing so, make sure your tests are standing on a strong foundation and that they follow unit tests' best practices — giving you confidence in going forward with the code cleanup and refactoring, knowing your actions will not break anything.

Result Builder

Reducing the amount of code to set up things like auto-layout constraints will certainly make the code more readable. While there are many ways to achieve that, you can check out the Result builders in Swift explained with code example article by A. van der Lee, in which he shows a neat custom solution for setting up view constraints in UIKit.

Any and Some

If your code uses generics, you’ve probably seen this error message: "Protocol can only be used as a generic constraint because it has Self or associated type requirements." In Combining opaque return types with primary associated types, you can find out how to leverage the powers of the any and some keywords. With their combination, you can improve your APIs and unlock exciting ways to write generic code in Swift.

Swift Project in 2023

Speaking of the community — specifically, the one around the Swift project — a variety of work is underway, mainly planned for the upcoming year. Because of this and the difficulty of keeping an eye on them, Apple's Core Team has decided to gather and make a list of current and future projects and focus areas (not all of them, though).

We hope that, after all the cleanups and refactoring, you can find enough time to set work aside and enjoy joyful times with your loved ones in the upcoming month. Thank you for reading through this edition and see you the next time!

Would you like to join the STRV team? We're hiring!

Share this article