SwiftLee https://www.avanderlee.com/ A weekly blog about Swift, iOS and Xcode Tips and Tricks Tue, 06 Dec 2022 08:33:48 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to use FormatStyle to restrict TextField input in SwiftUI https://www.avanderlee.com/swiftui/formatstyle-formatter-restrict-textfield-input/ Tue, 06 Dec 2022 08:33:45 +0000 https://www.avanderlee.com/?p=5997 A custom FormatStyle can help you control the allowed characters of a SwiftUI TextField. You might want to allow numbers only or a specific set of characters. While you could use a formatter in many cases, it’s good to know there’s a flexible solution using a custom FormatStyle implementation. In my case, I was looking … 

The post How to use FormatStyle to restrict TextField input in SwiftUI appeared first on SwiftLee.

]]>
Sheets in SwiftUI explained with code examples https://www.avanderlee.com/swiftui/presenting-sheets/ Tue, 29 Nov 2022 09:18:49 +0000 https://www.avanderlee.com/?p=5726 Sheets in SwiftUI allow you to present views that partly cover the underlying screen. You can present them using view modifiers that respond to a particular state change, like a boolean or an object. Views that partly cover the underlying screen can be a great way to stay in the context while presenting a new … 

The post Sheets in SwiftUI explained with code examples appeared first on SwiftLee.

]]>
@dynamicCallable in Swift explained with code examples https://www.avanderlee.com/swift/dynamiccallable/ Tue, 22 Nov 2022 09:32:05 +0000 https://www.avanderlee.com/?p=5715 It’s all in the name: @dynamicCallable in Swift allows you to dynamically call methods using an alternative syntax. While it’s primarily syntactic sugar, it can be good to know why it exists and how it can be used. We covered @dynamicMemberLookup earlier, allowing us to express member lookup rules in dynamic languages naturally. @dynamicCallable is … 

The post @dynamicCallable in Swift explained with code examples appeared first on SwiftLee.

]]>
Binary Targets in Swift Package Manager https://www.avanderlee.com/swift/binary-targets-swift-package-manager/ Tue, 15 Nov 2022 09:37:59 +0000 https://www.avanderlee.com/?p=5708 Binary Targets in Swift Package Manager (SPM) allow packages to declare xcframework bundles as available targets. The technique is often used to provide access to closed-source libraries and can improve CI performance by reducing time spent on fetching SPM repositories. Both downs and upsides are essential to consider when adding binary targets to your project. … 

The post Binary Targets in Swift Package Manager appeared first on SwiftLee.

]]>
Result builders in Swift explained with code examples https://www.avanderlee.com/swift/result-builders/ Tue, 08 Nov 2022 10:12:43 +0000 https://www.avanderlee.com/?p=4748 Result builders in Swift allow you to build up a result using ‘build blocks’ lined up after each other. They were introduced in Swift 5.4 and are available in Xcode 12.5 and up. Formerly known as function builders, you’ve probably already used them quite a bit by building a stack of views in SwiftUI. I … 

The post Result builders in Swift explained with code examples appeared first on SwiftLee.

]]>
Getting started with Unit Tests in Swift https://www.avanderlee.com/swift/unit-tests-best-practices/ Tue, 01 Nov 2022 08:57:10 +0000 https://www.avanderlee.com/?p=2203 Unit tests in programming languages ensure that written code works as expected. Given a particular input, you expect the code to come with a specific output. By testing your code, you’re creating confidence for refactors and releases, as you’ll ensure the code works as expected after running your suite of tests successfully. Many developers do … 

The post Getting started with Unit Tests in Swift appeared first on SwiftLee.

]]>
Refactoring Swift: Best Practices to succeed https://www.avanderlee.com/optimization/refactoring-swift-best-practices/ Tue, 25 Oct 2022 07:52:50 +0000 https://www.avanderlee.com/?p=5664 Refactoring code is part of the journey toward building sustainable apps. Whether you’re experienced or not: every developer refactors their code to improve its quality or readability. A refactor can be small enough to make you do it unconsciously, while bigger ones can become intimidating. I’ve been developing apps for over 10+ years in which … 

The post Refactoring Swift: Best Practices to succeed appeared first on SwiftLee.

]]>
Announcing the SwiftLee Talent Collective https://www.avanderlee.com/swift/swiftlee-talent-collective/ Tue, 18 Oct 2022 07:51:27 +0000 https://www.avanderlee.com/?p=5657 Today I’m excited to introduce you to the SwiftLee Talent Collective — an initiative to connect engineers with exciting companies. One of the most frequently asked questions I get relates to how to find a new job or how to make the next career step. I wrote about Swift Jobs: How to make the right … 

The post Announcing the SwiftLee Talent Collective appeared first on SwiftLee.

]]>
Alternate App Icon Configuration in Xcode https://www.avanderlee.com/swift/alternate-app-icon-configuration-in-xcode/ Tue, 11 Oct 2022 07:53:11 +0000 https://www.avanderlee.com/?p=5640 Adding alternate app icons to your app allows users to customize their home screen with an app icon that fits their style. An alternative icon could be a dark or light-mode version of the original icon or a collection of completely different styles. iOS 10.3 was the first version to support alternative icons. In the … 

The post Alternate App Icon Configuration in Xcode appeared first on SwiftLee.

]]>
Never keyword in Swift: return type explained with code examples https://www.avanderlee.com/swift/never-keyword/ Tue, 04 Oct 2022 07:20:26 +0000 https://www.avanderlee.com/?p=5631 The Never type in Swift allows you to tell the compiler about an exit point in your code. It’s a type with no values that prevents writing unuseful code by creating dead ends. While the type Never on its own might be a little unknown, you might have been using it already in your codebase. … 

The post Never keyword in Swift: return type explained with code examples appeared first on SwiftLee.

]]>