Skip to content

Instantly share code, notes, and snippets.

@below below/Sample.swift

Created Feb 28, 2020
Embed
What would you like to do?
Good SwiftUI/Combine?
struct ContentView: View {
@State private var input = ""
private var formatter: NumberFormatter
init () {
formatter = NumberFormatter()
formatter.numberStyle = .decimal
}
private func transform(string input: String) -> String {
let value = 3 * (formatter.number(from: input)?.doubleValue ?? 0)
return formatter.string(from: NSNumber(value: value)) ?? ""
}
var body: some View {
VStack(alignment: .leading) {
HStack {
Text("Input: ")
TextField("Type here", text: self.$input)
}
HStack {
Text("Output:")
Text(self.transform(string: self.input))
}
}.padding()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.