Latest

  1. Interesting ways of using Swift optionals

    A Swift tutorial explores lesser-known features of optionals beyond unwrapping with if let and guard let. It starts with "taking" an optional's value and resetting it to nil, using a TextViewModel that applies an accepted text suggestion, and shows a more elegant alternative to manually clearing the property.

  2. Using Swift’s ‘some’ keyword beyond SwiftUI

    A Swift guide explains how the some keyword, familiar from declaring SwiftUI view bodies, can be used beyond SwiftUI. It shows how some lets the compiler infer concrete types that would otherwise produce long nested generic signatures. The article then applies the keyword to generic function parameters and other generics-based problems as syntactic sugar, using a video app's Database type as an example.

  3. Why Swift is introducing a warning for weak captures within nested closures

    Swift 6.4, in beta as part of Xcode 27, introduces a warning when a nested closure weakly captures an object that its parent closure implicitly captures strongly. The diagnostic targets a common memory management bug where a weak self in an inner closure is undermined by a strong capture in the outer one. An example with a repeating Timer and a view model shows how the pattern can keep objects alive and how to fix it.

  4. Swift protocols and the main actor

    A Swift by Sundell tutorial explains how the @MainActor attribute interacts with protocol declaration and adoption in Swift. It shows that a protocol annotated with @MainActor isolates all its requirements and extensions to the main actor, using an example ErrorPresenter protocol with UIKit-based error presentation methods.

  5. Building a design system at Genius Scan

    An article describes building a design system for the Genius Scan app to keep UI consistent as its code base grows. It explains how margins, colors and fonts tend to diverge across components and how features built from scratch lead to duplicated effort. The piece argues that a design system of reusable components can be adopted incrementally rather than as a months-long rewrite.

  6. Deciding between ‘let’ and ‘var’ for Swift struct properties

    A Swift tutorial explains how choosing let or var for struct properties affects more than mutability. Declaring an optional property with let, for example, means a value must always be passed for it in the compiler-generated memberwise initializer, even when that value is nil. The guide uses a User struct to illustrate how each choice shapes the struct's behaviour.

  7. Decoding Swift types that require additional data

    Swift by Sundell covers decoding Swift types that need data not present in the serialized input. The Codable API, combining Encodable and Decodable, lets types like a Movie struct be serialized automatically when the JSON matches their structure. A User type with a favorites property shows the problem of initializing values whose required data is missing from the JSON.

  8. Tips and tricks for when using SwiftUI’s ViewBuilder

    Swift by Sundell offers tips for working with SwiftUI's ViewBuilder type, which lets multiple view expressions be declared within a scope such as a body property or a VStack or HStack closure without manual grouping. Developers often use SwiftUI for a long time without noticing ViewBuilder, because SwiftUI's closures and protocols, including the View protocol's body requirement, already carry the @ViewBuilder attribute.

  9. Using Swift’s defer keyword within async and throwing contexts

    Swift by Sundell explains using Swift's defer keyword, which delays a block of code until the current scope exits, in throwing and async contexts. Such code often has several exit points, making cleanup error-prone. An example SearchService actor must close a database connection on both success and error paths, a duplication that defer can remove.

  10. Modern URL construction in Swift

    A Swift by Sundell tutorial examines modern ways to construct URLs in Swift. It addresses how converting a string to Swift's URL type returns an optional, which feels unnecessary for static string literals, and why developers commonly resort to force unwrapping in those cases.

  11. Swift by Sundell is back!

    John Sundell has announced the return of Swift by Sundell after about two years of dormancy. He explains that becoming a father in the summer of 2022 made family his priority, leaving energy only for freelance work rather than articles and podcasting. Regaining a publishing routine proved difficult even as his time and sleep returned.

  12. SwiftUI views versus modifiers

    A Swift article explores the architectural difference between defining SwiftUI UI as a custom view type versus as a modifier, given that SwiftUI treats views as data describing UI rather than rendered pixels. Using a FeaturedLabel example that adds a star image, orange foreground color and headline font to text, it shows that the same result can be achieved with a View protocol extension and discusses when each approach fits.

  13. Observing the content offset of a SwiftUI ScrollView

    A SwiftUI tutorial explains how to observe the content offset of a ScrollView, which has no built-in API for reading scroll position. It notes that ScrollViewReader can change the position in code but cannot read it. Bridging to UIKit's UIScrollView delegate would require substantial extra code, so the guide presents a SwiftUI-native approach.

  14. Podcast: “The evolution of Swift”, with special guest Nick Lockwood

    In the final 2022 episode of the Swift by Sundell podcast, Nick Lockwood discusses how Swift and its ecosystem have evolved since the language's 2014 introduction. The conversation compares Swift with other modern languages such as Kotlin and Rust and considers its direction for 2023 and beyond, touching on Swift Concurrency, reflection, the Result type and a proposal for adding macros.

  15. Podcast: “Swift concurrency in practice”, with special guest Ben Scheirman

    A Swift by Sundell podcast episode features Ben Scheirman discussing how Swift's built-in concurrency features, including async/await and tasks, are used in practice when building apps for Apple's platforms. Topics referenced include Combine, Grand Central Dispatch, async sequences and the MainActor attribute.

  16. Combining opaque return types with primary associated types

    A Swift by Sundell tutorial shows how combining opaque return types with primary associated types reduces the need for type erasure with generic protocols. It contrasts this with earlier Swift, where returning a Combine Publisher required wrapping it in AnyPublisher because the compiler lacked information about the output and error types.

  17. Podcast: “Responsive and smooth UIs”, with special guest Adam Bell

    Adam Bell returns to the Swift by Sundell podcast to discuss techniques for optimizing UI code and using animations to make iOS apps feel fast and responsive. Topics referenced include Core Animation, CATransaction, Grand Central Dispatch, debouncing, view controller transitions, spring animation parameters and snapshotting UIViews.

  18. Podcast: “Freelancing and WWDC22 highlights”, with special guest Donny Wals

    Donny Wals returns to the Swift by Sundell podcast to talk about freelancing as an iOS developer and key additions from WWDC22. Topics include SwiftUI's NavigationStack and Layout protocol, Swift Charts, desktop-class iPad apps, UIHostingConfiguration, WidgetKit, Live Activities and Swift 5.7's new optional unwrapping syntax.

  19. Podcast: “The role of system design”, with special guest Gui Rambo

    Gui Rambo returns to John Sundell's podcast to discuss the role and importance of system design when building apps and open source tools. The episode looks at how common app architectures and design patterns such as MVVM and MVC can be augmented with custom systems.

  20. Podcast: “What’s new in SwiftUI in iOS 16?”, with special guest Natalia Panferova

    Natalia Panferova joins host John on a podcast episode about key new features coming to SwiftUI and UIKit in iOS 16, and about her experience working on SwiftUI at Apple. Topics include the Layout protocol, the new navigation APIs such as NavigationStack and NavigationSplitView, AnyLayout, ViewThatFits, new sheet APIs, Swift Charts, and rendering SwiftUI views inside UITableView or UICollectionView cells on iOS 16.