Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
CookThatBird - Day9
// ViewController.swift
// CookThatBird
// Created by Eloise Camire on 2014-10-15.
// Copyright (c) 2014 Eloise Camire. All rights reserved.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var numberPeopleField: UITextField!
@IBOutlet weak var turkeySizeLabel: UILabel!
@IBOutlet weak var thawTimeLabel: UILabel!
@IBOutlet weak var cookTimeLabel: UILabel!
let thawHoursPerPound: Double = 6
let cookingMinutePerPound: Double = 15
let poundPerPerson: Double = 1.5
func calculateTurkeySize (persons: Double) -> Double {
return persons * poundPerPerson
func calculateThawTime (turkeySize: Double) -> Double {
return turkeySize * thawHoursPerPound
func calculateCookTime (turkeySize: Double) -> Double {
return turkeySize * cookingMinutePerPound
@IBAction func calculateButtonPressed(sender: AnyObject) {
var people = (numberPeopleField.text as NSString).doubleValue
var turkeySize = calculateTurkeySize(people)
var thawTime = calculateThawTime(turkeySize)
var cookTime = calculateCookTime(turkeySize)
// convert decimal hour to hour & minutes and format to remove .0
var hours = floor(cookTime/60)
var minutes = floor(cookTime - (hours * 60))
var formatThawTime : NSString = NSString(format: "%.f", thawTime)
var formatHours : NSString = NSString(format: "%.f", hours)
var formatMinutes : NSString = NSString(format: "%.f", minutes)
turkeySizeLabel.text = "\(turkeySize) lbs"
thawTimeLabel.text = "\(formatThawTime) hours"
cookTimeLabel.text = "\(formatHours):\(formatMinutes) hours"
override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.
override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated.

Awesome, I am using this as an example to call functions, as I am doing the same course as you. Hope you dont mind.

Do you mind if I ask how you found out that information? I have tried for ages to work it out and couldnt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment