簡化程式碼
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickNumberButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="fKV-LM-t0P"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="fKV-LM-t0P"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nAR-KS-hdA">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nAR-KS-hdA">
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickNumberButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="3tS-Vs-uwN"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="3tS-Vs-uwN"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kDf-qC-jcV">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kDf-qC-jcV">
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickNumberButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="7dd-g7-d1V"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="7dd-g7-d1V"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JA3-GM-FCC">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JA3-GM-FCC">
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickNumberButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="SQe-6n-LS3"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="SQe-6n-LS3"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="lNe-oW-jh1">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="lNe-oW-jh1">
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickNumberButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="YHI-GM-GHt"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="YHI-GM-GHt"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="K0o-vl-kE7">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="K0o-vl-kE7">
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickNumberButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="fTX-1h-ZFC"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="fTX-1h-ZFC"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1p3-kG-6iM">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1p3-kG-6iM">
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickNumberButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="dK6-yT-RSF"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="dK6-yT-RSF"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wGn-JZ-stq">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wGn-JZ-stq">
|
||||||
@@ -105,7 +105,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickNumberButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="8jc-pf-wxa"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="8jc-pf-wxa"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XMC-8P-7aZ">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XMC-8P-7aZ">
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickNumberButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="X0L-rt-8nz"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="X0L-rt-8nz"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ePk-jK-elJ">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ePk-jK-elJ">
|
||||||
@@ -127,7 +127,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickNumberButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="5kj-8D-26R"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="5kj-8D-26R"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="caQ-65-jBq">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="caQ-65-jBq">
|
||||||
@@ -138,7 +138,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickDotButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="n4O-i6-tej"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="fpp-0T-t6o"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jgo-wI-dJm">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jgo-wI-dJm">
|
||||||
@@ -149,7 +149,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickEquationButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Wlj-nE-CFP"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="eyW-0b-i2h"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="I4O-WX-Rsc">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="I4O-WX-Rsc">
|
||||||
@@ -160,7 +160,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickInversionButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="qMX-2i-KY2"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="tu2-ee-UdF"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Dlz-OI-x3i">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Dlz-OI-x3i">
|
||||||
@@ -171,7 +171,7 @@
|
|||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickPercentButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="sKA-Mn-mXq"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="eB9-ym-MPP"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="icb-C3-YOh">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="icb-C3-YOh">
|
||||||
@@ -180,7 +180,7 @@
|
|||||||
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
||||||
<state key="normal" title="+"/>
|
<state key="normal" title="+"/>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickPlusButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Jtc-RR-BM3"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="k8G-ba-JDK"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JAI-XN-CDt">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JAI-XN-CDt">
|
||||||
@@ -189,7 +189,7 @@
|
|||||||
<fontDescription key="fontDescription" type="system" weight="light" pointSize="42"/>
|
<fontDescription key="fontDescription" type="system" weight="light" pointSize="42"/>
|
||||||
<state key="normal" title="-"/>
|
<state key="normal" title="-"/>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickMinusButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="F3p-G6-2vG"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="zte-8Z-2HO"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cuz-9a-BkO">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cuz-9a-BkO">
|
||||||
@@ -198,7 +198,7 @@
|
|||||||
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
||||||
<state key="normal" title="×"/>
|
<state key="normal" title="×"/>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickMultiplicationButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="QmT-uo-S8J"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="wqp-oo-6PZ"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RA4-Vt-6OG">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RA4-Vt-6OG">
|
||||||
@@ -207,7 +207,7 @@
|
|||||||
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
||||||
<state key="normal" title="÷"/>
|
<state key="normal" title="÷"/>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickDivisionButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="JbS-w3-mTU"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="JKP-ji-JNS"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="K66-JV-tKt">
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="K66-JV-tKt">
|
||||||
@@ -216,7 +216,7 @@
|
|||||||
<fontDescription key="fontDescription" type="system" pointSize="22"/>
|
<fontDescription key="fontDescription" type="system" pointSize="22"/>
|
||||||
<state key="normal" title="AC"/>
|
<state key="normal" title="AC"/>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="clickAllClearButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Ovk-lI-xeN"/>
|
<action selector="clickButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="gEZ-Ma-WBZ"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hLf-ut-UVB">
|
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hLf-ut-UVB">
|
||||||
|
|||||||
@@ -9,56 +9,14 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class Calculator {
|
class Calculator {
|
||||||
var formula: String = ""
|
var formula = ""
|
||||||
var result: String = ""
|
var result = ""
|
||||||
|
|
||||||
func clickNumber(_ number: Int) {
|
func click(_ text: String) {
|
||||||
formula += String(number)
|
if text == "AC" {
|
||||||
result += String(number)
|
formula = ""
|
||||||
}
|
} else {
|
||||||
|
formula += text
|
||||||
func clickDot() {
|
}
|
||||||
formula += "."
|
|
||||||
result += "."
|
|
||||||
}
|
|
||||||
|
|
||||||
func clickEquation() {
|
|
||||||
formula += "="
|
|
||||||
result += "="
|
|
||||||
}
|
|
||||||
|
|
||||||
func clickPlus() {
|
|
||||||
formula += "+"
|
|
||||||
result += "+"
|
|
||||||
}
|
|
||||||
|
|
||||||
func clickMinus() {
|
|
||||||
formula += "-"
|
|
||||||
result += "-"
|
|
||||||
}
|
|
||||||
|
|
||||||
func clickMultiplication() {
|
|
||||||
formula += "*"
|
|
||||||
result += "*"
|
|
||||||
}
|
|
||||||
|
|
||||||
func clickDivision() {
|
|
||||||
formula += "/"
|
|
||||||
result += "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
func clickPercent() {
|
|
||||||
formula += "%"
|
|
||||||
result += "%"
|
|
||||||
}
|
|
||||||
|
|
||||||
func clickInversion() {
|
|
||||||
formula += "+/-"
|
|
||||||
result += "+/-"
|
|
||||||
}
|
|
||||||
|
|
||||||
func clickAllClear() {
|
|
||||||
formula = ""
|
|
||||||
result = ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,60 +15,14 @@ class ViewController: UIViewController {
|
|||||||
@IBOutlet weak var resultLabel: UILabel!
|
@IBOutlet weak var resultLabel: UILabel!
|
||||||
@IBOutlet var numberButtons: [UIButton]!
|
@IBOutlet var numberButtons: [UIButton]!
|
||||||
|
|
||||||
var calculator: Calculator = Calculator()
|
var calculator = Calculator()
|
||||||
|
|
||||||
@IBAction func clickNumberButton(_ sender: UIButton) {
|
@IBAction func clickButton(_ sender: UIButton) {
|
||||||
let number = numberButtons.firstIndex(of: sender)!
|
calculator.click(sender.currentTitle!)
|
||||||
calculator.clickNumber(number)
|
updateView()
|
||||||
updateFormulaAndResult()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func clickDotButton(_ sender: UIButton) {
|
func updateView() {
|
||||||
calculator.clickDot()
|
|
||||||
updateFormulaAndResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func clickEquationButton(_ sender: UIButton) {
|
|
||||||
calculator.clickEquation()
|
|
||||||
updateFormulaAndResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func clickPlusButton(_ sender: UIButton) {
|
|
||||||
calculator.clickPlus()
|
|
||||||
updateFormulaAndResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func clickMinusButton(_ sender: UIButton) {
|
|
||||||
calculator.clickMinus()
|
|
||||||
updateFormulaAndResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func clickMultiplicationButton(_ sender: UIButton) {
|
|
||||||
calculator.clickMultiplication()
|
|
||||||
updateFormulaAndResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func clickDivisionButton(_ sender: UIButton) {
|
|
||||||
calculator.clickDivision()
|
|
||||||
updateFormulaAndResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func clickPercentButton(_ sender: UIButton) {
|
|
||||||
calculator.clickPercent()
|
|
||||||
updateFormulaAndResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func clickInversionButton(_ sender: UIButton) {
|
|
||||||
calculator.clickInversion()
|
|
||||||
updateFormulaAndResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func clickAllClearButton(_ sender: UIButton) {
|
|
||||||
calculator.clickAllClear()
|
|
||||||
updateFormulaAndResult()
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateFormulaAndResult() {
|
|
||||||
formulaLabel.text = calculator.formula
|
formulaLabel.text = calculator.formula
|
||||||
resultLabel.text = calculator.result
|
resultLabel.text = calculator.result
|
||||||
}
|
}
|
||||||
@@ -78,7 +32,7 @@ class ViewController: UIViewController {
|
|||||||
// Do any additional setup after loading the view.
|
// Do any additional setup after loading the view.
|
||||||
borderView.layer.borderWidth = 1
|
borderView.layer.borderWidth = 1
|
||||||
borderView.layer.borderColor = #colorLiteral(red: 0.8374180198, green: 0.8374378085, blue: 0.8374271393, alpha: 1)
|
borderView.layer.borderColor = #colorLiteral(red: 0.8374180198, green: 0.8374378085, blue: 0.8374271393, alpha: 1)
|
||||||
updateFormulaAndResult()
|
updateView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user