# Swift Default Value in String Interpolations

DevFeed: [Swift Default Value in String Interpolations](<https://devfeed.tech/articles/swift-default-value-in-string-interpolations-21087.md>)

Original publisher: [Read original article](<https://useyourloaf.com/blog/swift-default-value-in-string-interpolations/>)

Author: Keith Harrison

Published: 2025-09-07T08:51:46Z

Content type: tutorial

Language: en

Sources: [K. Harrison](<https://devfeed.tech/sources/k-harrison.md>)

Topics: [Swift](<https://devfeed.tech/topics/swift.md>), [SwiftUI](<https://devfeed.tech/topics/swiftui.md>), [Localization (l10n)](<https://devfeed.tech/topics/localization.md>)

Tags: [auto-layout](<https://devfeed.tech/tags/auto-layout.md>), [ios](<https://devfeed.tech/tags/ios.md>), [learn](<https://devfeed.tech/tags/learn.md>), [objective-c](<https://devfeed.tech/tags/objective-c.md>), [swift](<https://devfeed.tech/tags/swift.md>), [swift-6-2](<https://devfeed.tech/tags/swift-6-2.md>), [wwdc](<https://devfeed.tech/tags/wwdc.md>), [xcode](<https://devfeed.tech/tags/xcode.md>)

## AI overview

Swift 6.2 adds a default value parameter for string interpolation, allowing optional values of any type to use a specified fallback string. The article also notes that this parameter does not currently work with LocalizedStringKey.

## Source excerpt

Swift 6.2 makes it easier to interpolate strings with optional values. What's The Problem? In this SwiftUI view I need to create a text string from an optional integer value: struct CounterView: View { let count: Int? var body: some View { Text("The count is \(count)") } } The compiler warns about the optional value: String interpolation produces a debug description for an optional value; did you mean to make this explicit? The compiler suggests either providing a default value or to use String(describing:) to silence the warning. Using the nil-coalescing operator to provide a default value removes the warning but is not ideal. The default value has to match the type of the optional value. That can work when dealing with an optional string. In this example I have an optional Int and there may not be a sensible default value for the nil case. For example, I could use zero: // The count is 0 Text("The count is \(count ?? 0)") The alternative of using the String(describing:) approach is both clumsy and ends up showing the nil value: // The count is nil Text("The count is \(String(describing: count))") What I want is a way to provide a default string regardless of the type of the optional value. Default Value Parameter In Swift 6.2, String interpolation has a new default value parameter that accepts a string regardless of the type of the optional value: // The count is not set Text("The count is \(count, default: "not set")") That's an improvement over outputting nil. Localization One issue is that I've been unable to get this to work with localization. The problem seems to be that LocalizedStringKey doesn't support the default value parameter. So this doesn't work: // Not Supported let key = LocalizedStringKey("The count is: \(count, default: "not set")") Learn More SE-0477 Default Value in String Interpolations Swift Default Value in String Interpolations was originally posted 07 Sep 2025 on useyourloaf.com. Want this direct to your inbox? Sign up and get my free WWDC