Last active
February 2, 2020 21:56
-
-
Save donguri9/20ef9b607cabf28bbab30b1c4f4aec83 to your computer and use it in GitHub Desktop.
Calculator20200130
This file contains 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 var display = 0 | |
@State var currentValue = 0 | |
@State var useIsInTheMiddleOfTyping = false | |
@State var first = 0 | |
@State var second = 0 | |
@State var operand = "+" | |
@State var typingNow = false | |
var body: some View { | |
VStack{ | |
Text(String(display)) | |
.padding() | |
Button("数字ボタン1"){ | |
self.first = 9 | |
self.display = self.first | |
}.padding() | |
Button("演算子[+]ボタン"){ | |
self.operand = "-" | |
}.padding() | |
Button("数字ボタン2"){ | |
self.second = 5 | |
self.display = self.second | |
}.padding() | |
Button("演算子[=]ボタン"){ | |
switch self.operand{ | |
case "+": | |
self.display = self.first + self.second | |
case "-": | |
self.display = self.first - self.second | |
default: | |
print("演算子なし!") | |
} | |
// if self.operand == "+"{ | |
// self.display = self.first + self.second | |
// } | |
}.padding() | |
Button("AC"){ | |
self.display = 0 | |
}.padding() | |
} | |
} | |
} | |
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