Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instance method 'appendInterpolation' requires that 'Decimal' conform to '_FormatSpecifiable' when attempting to use in SwiftUI [duplicate]

Tags:

swift

swiftui

import Foundation
import SwiftUI

struct SampleComponent: View {
  @Binding var value: Decimal

  var body: some View {
    return Text("\(value)")
  }
}

Gives me the error:

Instance method 'appendInterpolation' requires that 'Decimal' conform to '_FormatSpecifiable'

This works fine in a playground though:

import Foundation

var d: Decimal = 4.5
print("\(d)")

Any idea what's going on or how to fix it?

like image 759
Senseful Avatar asked Jun 28 '20 17:06

Senseful


1 Answers

Not exactly sure why it gives this error, but one solution is to cast it to a String:

Text("\(value)" as String)
like image 118
Senseful Avatar answered Nov 10 '22 06:11

Senseful