index.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!doctype html>
  2. <title>CodeMirror: Swift mode</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../../doc/docs.css">
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="../../addon/edit/matchbrackets.js"></script>
  8. <script src="./swift.js"></script>
  9. <style>
  10. .CodeMirror { border: 2px inset #dee; }
  11. </style>
  12. <div id=nav>
  13. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  14. <ul>
  15. <li><a href="../../index.html">Home</a>
  16. <li><a href="../../doc/manual.html">Manual</a>
  17. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  18. </ul>
  19. <ul>
  20. <li><a href="../index.html">Language modes</a>
  21. <li><a class=active href="#">Swift</a>
  22. </ul>
  23. </div>
  24. <article>
  25. <h2>Swift mode</h2>
  26. <form><textarea id="code" name="code">
  27. //
  28. // TipCalculatorModel.swift
  29. // TipCalculator
  30. //
  31. // Created by Main Account on 12/18/14.
  32. // Copyright (c) 2014 Razeware LLC. All rights reserved.
  33. //
  34. import Foundation
  35. class TipCalculatorModel {
  36. var total: Double
  37. var taxPct: Double
  38. var subtotal: Double {
  39. get {
  40. return total / (taxPct + 1)
  41. }
  42. }
  43. init(total: Double, taxPct: Double) {
  44. self.total = total
  45. self.taxPct = taxPct
  46. }
  47. func calcTipWithTipPct(tipPct: Double) -> Double {
  48. return subtotal * tipPct
  49. }
  50. func returnPossibleTips() -> [Int: Double] {
  51. let possibleTipsInferred = [0.15, 0.18, 0.20]
  52. let possibleTipsExplicit:[Double] = [0.15, 0.18, 0.20]
  53. var retval = [Int: Double]()
  54. for possibleTip in possibleTipsInferred {
  55. let intPct = Int(possibleTip*100)
  56. retval[intPct] = calcTipWithTipPct(possibleTip)
  57. }
  58. return retval
  59. }
  60. }
  61. </textarea></form>
  62. <script>
  63. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  64. lineNumbers: true,
  65. matchBrackets: true,
  66. mode: "text/x-swift"
  67. });
  68. </script>
  69. <p>A simple mode for Swift</p>
  70. <p><strong>MIME types defined:</strong> <code>text/x-swift</code> (Swift code)</p>
  71. </article>