Created
May 28, 2021 10:54
-
-
Save denisenepraunig/5d1097d350d6795e34654bededbd3f9e to your computer and use it in GitHub Desktop.
Number Converter - Day 19: 100 Days of SwiftUI #100daysOfSwiftUI
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
import SwiftUI | |
struct ContentView: View { | |
@State private var numberString = "0" | |
private var numberInt: Int { | |
Int(numberString) ?? 0 | |
} | |
private var numberHex: String { | |
String(numberInt, radix: 16).uppercased() | |
} | |
private var numberBinary: String { | |
String(numberInt, radix: 2) | |
} | |
var body: some View { | |
NavigationView { | |
Form { | |
Section(header: Text("Decimal Input")) { | |
TextField("Decimal number", text: $numberString) | |
.keyboardType(.numberPad) | |
} | |
Section(header: Text("HEX Output")) { | |
Text(numberHex) | |
} | |
Section(header: Text("Binary Output")) { | |
Text(numberBinary) | |
} | |
} | |
.navigationBarTitle("Number Converter") | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Number Converter Interface:
Decimal Input, Hex Output, Binary Output
Number pad keyboard