Dominika Gajdova3 min

Swiftly Highlights: What To Know in 2024

EngineeringDec 20, 2023

New year, new Swiftly picks we uncovered in December! As we dive into 2024, let’s kick off the year with a forecast and uncover exciting insights about our beloved Swift language.

What To Look For in 2024

While there is no official date yet, 2024 could very well be the year Swift 6 gets released, entering a new era of even better Swift. If you haven’t already, make sure to start new projects or update your current ones with the Strict concurrency checking complete setting, as it will be required by the language itself.

Vapor 5, the community’s favorite web framework, is also highly anticipated for release this year — bringing Swift 6 support, complete thread safety and additional features such as middleware, Swift HTTP types, distributed tracing and more.

Allegedly, Apple Vision Pro devices have commenced mass production, and the first shipments are expected to be dispatched by the end of January. We are one step closer to introducing the general public to the new era of AR, and it's time for us developers to craft amazing virtual experiences.

What’s New

The Swift proposal for typed errors is currently under active review and appears to be a promising improvement to error handling. The proposal aims to introduce the option of specifying a concrete error type using the 'throws' keyword, similar to how languages like Java or C# implement it.

Better Code

As a statically typed language, Swift offers a variety of methods for typecasting one entity to another. Mastering these mechanisms safely and efficiently is crucial to becoming a proficient Swift developer. A Comprehensive Guide to Typecasting will walk you through all there is to know about type casting in Swift. 

State machines are an incredibly useful and powerful programming technique. Typestate is a design pattern that originates from languages with advanced type systems and strict memory ownership models such as Rust. What simple state machine implementations lack is the full definition of the transition function. In other words, covering all allowed transitions from one state to another while also considering forbidden and undefined transitions. Previously, defining transitions was possible using nested enums or simple yet more sophisticated libraries. The Typestate pattern approaches it differently using a new Swift 5.9 noncopyable feature.

Performance

Swift’s compiler optimizes your code effectively. However, there are specific actions you can take to further assist the compiler in generating even faster code. 

One such action is to consider using the 'final' keyword in cases where the class isn’t designed to be subclassed. Swift employs a dynamic dispatch mechanism to determine the appropriate method/property implementation when using classes and inheritance. Dynamic dispatch enhances language expressiveness but introduces a constant amount of runtime overhead. Using the 'final' keyword informs the compiler of the impossibility of overriding and subclassing, allowing the compiler to employ static dispatch instead.

Functional higher-order functions — such as map, filter or reduce — enable us to write clean and neat-looking code as opposed to writing procedural for loops. However, are there any performance benefits to them as well? While the assumption is that both approaches have the same time complexity (which is correct), Swift’s higher-order functions are implemented with memory optimizations in mind. They prove to be noticeably more performant, thanks to concepts such as loop unrolling and the elimination of temporary variables.

If you're fond of utilizing the '.init()' shortcut, it's advised to avoid it, particularly in the context of computed variables. Lucas van Dongen delves into a detailed comparison of compilation speed performance among various initialization methods.

iCloud & AppStore Connect

Have you ever needed an app to store files in the Files directory while ensuring synchronization with a user's other Apple devices? Apple's iCloud Documents provide a cloud storage and synchronization service, enabling users to effortlessly store, access and share their documents and files. 

While syncing documents is straightforward as the default use case, what about saving non-document files to iCloud Documents?

We can all acknowledge the challenge of providing correctly sized assets for your app on AppStore Connect, as Apple's requirements are not always clearly communicated. App screenshots must align with specific device screen sizes, namely 5.5 inches for standard iPhones and either 6.5 or 6.7 inches for larger iPhone models. If your app exclusively supports iOS 17 and above, there is no device with a 5.5-inch screen on which your app will run. However, AppStore Connect still requires you to upload screenshots for this size. An often overlooked detail is that the option also accepts an alternative for 4.7-inch screens, like the latest iPhone SE, which does support iOS 17.

That’s it for this edition of Swiftly Highlights! Hope it was a good read. See you next time.

Share this article



Sign up to our newsletter

Monthly updates, real stuff, our views. No BS.