Created
August 18, 2015 00:39
-
-
Save jonathanbarton/a060fbaefc2dbe79b711 to your computer and use it in GitHub Desktop.
accessor example
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
// | |
// BillManager.swift | |
// SushiOrder | |
// | |
// Created by Jonathan Barton on 8/17/15. | |
// Copyright (c) 2015 Jonathan Barton. All rights reserved. | |
// | |
import UIKit | |
class BillManager: NSObject { | |
private let prices = ["sushi": 100, "tuna": 200, "rolls": 50, "sake": 10] | |
private var total:Int | |
init(actualTotal:Int = 0) { | |
total = actualTotal | |
} | |
func addOrder(order:String) { | |
if let tot = prices[order] { | |
total += tot | |
} | |
} | |
var currentTotal: String { | |
get { | |
return total.description | |
} | |
} | |
} | |
//============================================ | |
// | |
// ViewController.swift | |
// SushiOrder | |
// | |
// Created by Jonathan Barton on 8/17/15. | |
// Copyright (c) 2015 Jonathan Barton. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
// MARK: connections | |
@IBOutlet weak var total: UILabel! | |
@IBOutlet weak var totalWithTip: UILabel! | |
// MARK: controller items | |
private let billManager = BillManager() | |
// MARK: overloads | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
// MARK: custom methods | |
private func showTotal() { | |
total.text = billManager.currentTotal | |
} | |
// MARK: ui interactions | |
@IBAction func onRolls(sender: AnyObject) { | |
billManager.addOrder("rolls") | |
showTotal() | |
} | |
@IBAction func onTunas(sender: AnyObject) { | |
} | |
@IBAction func onSake(sender: AnyObject) { | |
} | |
@IBAction func onSushi(sender: AnyObject) { | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment