-
Notifications
You must be signed in to change notification settings - Fork 469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BMI Calculator complete with dynamic state management based on variou… #7
Open
mdigel
wants to merge
1
commit into
appbrewery:master
Choose a base branch
from
mdigel:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// ViewController.swift | ||
// BMI Calculator | ||
// | ||
// Created by Angela Yu on 21/08/2019. | ||
// Copyright © 2019 Angela Yu. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class CalculateViewController: UIViewController { | ||
@IBOutlet weak var heightSlider: UISlider! | ||
@IBOutlet weak var weightSlider: UISlider! | ||
@IBOutlet weak var heightLabel: UILabel! | ||
@IBOutlet weak var weightLabel: UILabel! | ||
|
||
// var bmiValue = "0.0" | ||
var calculatorBrain = CalculatorBrain() | ||
|
||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
// Do any additional setup after loading the view. | ||
} | ||
|
||
@IBAction func heightSliderChanged(_ sender: UISlider) { | ||
let currentValue = sender.value | ||
let roundedValue = (currentValue*100).rounded()/100 | ||
print(roundedValue) | ||
heightLabel.text = "\(roundedValue)m" | ||
} | ||
|
||
@IBAction func weightSliderChanged(_ sender: UISlider) { | ||
let currentValue = Int(sender.value) | ||
print(currentValue) | ||
weightLabel.text = "\(currentValue)Kg" | ||
|
||
} | ||
|
||
@IBAction func calculatePressed(_ sender: UIButton) { | ||
let height = heightSlider.value | ||
let weight = weightSlider.value | ||
|
||
calculatorBrain.calculateBMI(height: height, weight: weight) | ||
|
||
|
||
// Manual way to create modal pop up on a custom class | ||
// let secondVC = SecondViewController() | ||
// secondVC.bmiValue = String(format: "%.1f", bmi) | ||
// self.present(secondVC, animated: true, completion: nil) | ||
|
||
|
||
// for navigating btw screens that have a segue created on Main.storyboard | ||
self.performSegue(withIdentifier: "goToResults", sender: self) | ||
|
||
|
||
} | ||
|
||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | ||
//print("sender", sender.bmi!) | ||
|
||
if segue.identifier == "goToResults" { | ||
// narrow down the data type and specify the exact type the desination will be | ||
let destinationVC = segue.destination as! ResultsViewController | ||
destinationVC.bmiValue = calculatorBrain.getBMIValue() | ||
destinationVC.advice = calculatorBrain.getAdvice() | ||
destinationVC.color = calculatorBrain.getColor() | ||
|
||
} | ||
} | ||
|
||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// ResultsViewController.swift | ||
// BMI Calculator | ||
// | ||
// Created by Matthew Digel on 12/19/20. | ||
// Copyright © 2020 Angela Yu. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class ResultsViewController: UIViewController { | ||
@IBOutlet weak var bmiLabel: UILabel! | ||
@IBOutlet weak var adviceLabel: UILabel! | ||
@IBOutlet weak var backgroundView: UIImageView! | ||
|
||
var bmiValue: String? | ||
var advice: String? | ||
var color: UIColor? | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
bmiLabel.text = bmiValue | ||
adviceLabel.text = advice | ||
view.backgroundColor = color | ||
|
||
// Could also do background Color this way: | ||
// backgroundView.backgroundColor = color | ||
} | ||
|
||
@IBAction func recalculatePressed(_ sender: UIButton) { | ||
// can use self too | ||
// self.dismiss(animated: true, completion: nil) | ||
dismiss(animated: true, completion: nil) | ||
} | ||
|
||
|
||
/* | ||
// MARK: - Navigation | ||
|
||
// In a storyboard-based application, you will often want to do a little preparation before navigation | ||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | ||
// Get the new view controller using segue.destination. | ||
// Pass the selected object to the new view controller. | ||
} | ||
*/ | ||
|
||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// BMI.swift | ||
// BMI Calculator | ||
// | ||
// Created by Matthew Digel on 12/19/20. | ||
// Copyright © 2020 Angela Yu. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
struct BMI { | ||
let value: Float | ||
let advice: String | ||
let color: UIColor | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import UIKit | ||
|
||
struct CalculatorBrain { | ||
var bmi: BMI? | ||
|
||
mutating func calculateBMI(height: Float, weight: Float){ | ||
let bmiValue = weight / pow(height, 2) | ||
if bmiValue < 18.5 { | ||
// print("Underweight") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The commented print statement can be removed |
||
bmi = BMI(value: bmiValue, advice: "Eat More Pies", color: #colorLiteral(red: 0.2884203767, green: 0.749411387, blue: 1, alpha: 1)) | ||
|
||
} else if bmiValue < 24.9 { | ||
print("Normal") | ||
bmi = BMI(value: bmiValue, advice: "You are fit", color: #colorLiteral(red: 0.4666666687, green: 0.7647058964, blue: 0.2666666806, alpha: 1)) | ||
|
||
} else { | ||
print("Overweight") | ||
bmi = BMI(value: bmiValue, advice: "Eat Less Pies", color: #colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1)) | ||
} | ||
|
||
} | ||
|
||
func getBMIValue() -> String { | ||
let BMIValue = bmi?.value | ||
|
||
return String(format: "%.1f", BMIValue ?? "0.0") | ||
} | ||
|
||
func getAdvice () -> String { | ||
return bmi?.advice ?? "No advice" | ||
} | ||
|
||
func getColor () -> UIColor { | ||
return bmi?.color ?? UIColor.white | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commented print statement can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hello?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whaaat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clueless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hello
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi