Created
February 28, 2020 10:08
-
-
Save below/411f2b32986facbe670f792cf7b3aca5 to your computer and use it in GitHub Desktop.
Good SwiftUI/Combine?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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