Swift mode

x
 
1
//
2
//  TipCalculatorModel.swift
3
//  TipCalculator
4
//
5
//  Created by Main Account on 12/18/14.
6
//  Copyright (c) 2014 Razeware LLC. All rights reserved.
7
//
8
9
import Foundation
10
11
class TipCalculatorModel {
12
13
  var total: Double
14
  var taxPct: Double
15
  var subtotal: Double {
16
    get {
17
      return total / (taxPct + 1)
18
    }
19
  }
20
21
  init(total: Double, taxPct: Double) {
22
    self.total = total
23
    self.taxPct = taxPct
24
  }
25
26
  func calcTipWithTipPct(tipPct: Double) -> Double {
27
    return subtotal * tipPct
28
  }
29
30
  func returnPossibleTips() -> [Int: Double] {
31
32
    let possibleTipsInferred = [0.15, 0.18, 0.20]
33
    let possibleTipsExplicit:[Double] = [0.15, 0.18, 0.20]
34
35
    var retval = [Int: Double]()
36
    for possibleTip in possibleTipsInferred {
37
      let intPct = Int(possibleTip*100)
38
      retval[intPct] = calcTipWithTipPct(possibleTip)
39
    }
40
    return retval
41
42
  }
43
44
}
45

A simple mode for Swift

MIME types defined: text/x-swift (Swift code)