Commit 64e3d50c authored by Dennis Rassmann's avatar Dennis Rassmann Committed by Dennis Rassmann

adding function

parent 2a682f85
# Created by https://www.gitignore.io/api/osx,swift,objective-c,xcode
### Objective-C ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
iOSInjectionProject/
### Objective-C Patch ###
### OSX ###
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Swift ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
## Various settings
## Other
## Obj-C/Swift specific
## Playgrounds
timeline.xctimeline
playground.xcworkspace
# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
.build/
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control
### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
## Various settings
## Other
### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
# End of https://www.gitignore.io/api/osx,swift,objective-c,xcode
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
This diff is collapsed.
......@@ -9,7 +9,91 @@
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var resultLabel: UILabel!
var hasDecimalPoint = false
var firstNumber = 0.0
var secondNumber = 0.0
var operation = ""
@IBAction func doCalc(_ sender: UIButton) {
var result = 0.0;
if (firstNumber != 0) {
secondNumber = Double(resultLabel.text!)!
switch (operation) {
case "+":
result = Double(firstNumber + secondNumber)
break
case "-":
result = Double(firstNumber - secondNumber)
break
case "x":
result = Double(firstNumber * secondNumber)
break
case ":":
if (secondNumber != 0) {
result = Double(firstNumber / secondNumber)
} else {
resultLabel.text = "0.0"
resetCalc()
}
break
default:
return
}
resultLabel.text = "\(result)"
}
}
@IBAction func opTapped(_ sender: UIButton) {
operation = sender.currentTitle ?? ""
firstNumber = Double(resultLabel.text!)!
resetResultLabel()
}
@IBAction func resetResult(_ sender: Any) {
resetWhole()
}
func resetResultLabel() {
resultLabel.text = "0"
hasDecimalPoint = false
}
func resetCalc() {
firstNumber = 0
secondNumber = 0
operation = ""
}
func resetWhole() {
resetResultLabel()
resetCalc()
}
@IBAction func btnTapped(_ sender: UIButton) {
let number = sender.currentTitle ?? "0"
//only one decimal point for each number
if (number == ".") {
if (!hasDecimalPoint) {
hasDecimalPoint = true
} else if (hasDecimalPoint) {
return
}
}
if (resultLabel.text == "0" && number != ".") {
resultLabel.text = number
} else {
resultLabel.text = resultLabel.text! + number
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment