Swift
Learn more and get better in Swift using this list of Swift blog posts, tutorials, tips, and tricks.
If and switch expressions in Swift
Swift 5.9 introduced if and switch expressions that allow you to write shorter code by omitting the return keyword. The feature resembles Swift 5.1's ability to omit the return keyword in single expressions inside closures. While shorter code doesn't necessarily always lead to more readable code, omitting return keywords inside ...
Predicate Macro in Swift for filtering and searching
#Predicate is a new Macro available since Swift 5.9 and Xcode 15, allowing you to filter or search a data collection. It can be seen as a replacement for the old-fashioned NSPredicate we're used to from the Objective-C days. The new Predicate is available as a Macro. If you're new ...
SwiftSyntax: Parse and Generate Swift source code
SwiftSyntax is a collection of Swift libraries that allow you to parse, inspect, generate, and adjust Swift source code. It was initially developed by Apple and is currently maintained as an open-source library with many contributors. You can find documentation on swiftpackageindex.com and many articles in the GitHub readme. The SwiftSyntax ...
@backDeployed to extend function availability to older OS releases
The @backDeployed attribute in Swift allows you to extend function availability back to older OS versions. It's beneficial for framework developers to make new declarations available to apps with a lower minimum deployment target compared to the framework. SE 376 Function Back Deployment introduced the attribute as a proposal, after ...
Swift Macros: Extend Swift with New Kinds of Expressions
Swift Macros got introduced in the WWDC 2023 release of Swift 5.9. They are a new way for you to extend Swift with new kinds of expressions, allow creating of expressive libraries, and eliminate extraneous boilerplate. As part of the vision of Macros, Swift Macros introduce a new way to ...
Share Swift Code between Swift On Server Vapor and Client App
Sharing Swift code between a backend and client app is one of the benefits you'll get when working with Swift on a Server. You can create dedicated Swift Packages containing sharable logic for both client and backend. While many developers mention sharing Swift code as one of the benefits of ...
Ranges in Swift explained with code examples
Ranges in Swift allow us to select parts of Strings, collections, and other types. They're the Swift variant of NSRange which we know from Objective-C, although they're different in usage, as I'll explain in this blog post. Ranges allow us to write elegant Swift code by using the range operator ...
Optimizing your app for Network Reachability
Network Reachability is a vital aspect of apps that use some networking capabilities. Your users won't always have a good internet connection, so optimizing your app for bad networking conditions is essential. We can leverage several techniques to optimize our app accordingly, but it's essential to be aware of common ...
The operation couldn’t be completed: solving errors in Swift
"The operation couldn't be completed" is a common error to receive from Apple's standard SDKs or 3rd party libraries. The errors often come with an error code that doesn't have a description, leaving you behind with unclear directions on solving the issue. I've been running into these errors quite often, ...
Equatable conformance in Swift explained with code examples
Equatable conformance allows you to compare one object with another. Based on whether the objects match, you can perform a specific operation. You can rely on default comparison implementations or custom logic to compare two objects. Many standard types are already comparable, but you must implement protocol conformance for your ...
Detached Tasks in Swift explained with code examples
Detached tasks allow you to create a new top-level task and disconnect from the current structured concurrency context. You could argue that using them results in unstructured concurrency since you're disconnecting potentially relevant tasks. While it sounds terrible to disconnect from structured concurrency, there are still examples of use cases ...
Task Groups in Swift explained with code examples
Task Groups in Swift allow you to combine multiple parallel tasks and wait for the result to return when all tasks are finished. They are commonly used for tasks like combining multiple API request responses into a single response object. Read my article about tasks first if you're new to ...