# Issues with custom string interpolation in SwiftUI Text Views

**URL:** <https://forums.swift.org/t/issues-with-custom-string-interpolation-in-swiftui-text-views/35361>\
**Category:** Using Swift\
**Tags:** off-topic, swiftui\
**Created:** [April 14, 2020, 8:56am UTC](https://forums.swift.org/t/issues-with-custom-string-interpolation-in-swiftui-text-views/35361 "2020-04-14T08:56:47Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![odmir](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/odmir/32/4784_2.png) [@odmir](https://forums.swift.org/u/odmir)\
**Post date:** [April 15, 2020, 11:12pm UTC](https://forums.swift.org/t/issues-with-custom-string-interpolation-in-swiftui-text-views/35361/9 "2020-04-15T23:12:46Z")

</div>

> [@Peter-Schorn](#):
>
> I would like to know if I can write just a single function in a protocol extension so that I don't have to duplicate code

Making a new protocol with the correct required method and extension, and then extending `LocalizedStringKeys/String.StringInterpolation` with this new protocol seems to work for me:

```swift
protocol Formattable {
    mutating func appendInterpolation(_: String)
}

extension Formattable {
    mutating func appendInterpolation(_ value: Double, format: String) {
        appendInterpolation(String(format: format, value))
    }
}

extension LocalizedStringKey.StringInterpolation: Formattable {}
extension String.StringInterpolation: Formattable {}

```

---

_[View the full topic](https://forums.swift.org/t/issues-with-custom-string-interpolation-in-swiftui-text-views/35361)._
