You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.7 KiB

2 months ago
  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="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></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/codemirror5">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. protocol HeaderViewProtocol {
  28. func setTitle(_ string: String)
  29. }
  30. struct AnyHeaderView {
  31. let view: UIView
  32. let headerView: HeaderViewProtocol
  33. init<T: UIView>(view: T) where T: HeaderViewProtocol {
  34. self.view = view
  35. self.headerView = view
  36. }
  37. }
  38. let header = AnyHeaderView(view: myView)
  39. header.headerView.setTitle("hi")
  40. struct HeaderView {
  41. let view: UIView
  42. let setTitle: (String) -> ()
  43. }
  44. var label = UILabel()
  45. let header = HeaderView(view: label) { str in
  46. label.text = str
  47. }
  48. header.setTitle("hello")
  49. </textarea></form>
  50. <script>
  51. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  52. lineNumbers: true,
  53. matchBrackets: true,
  54. mode: "text/x-swift"
  55. });
  56. </script>
  57. <p>A simple mode for Swift</p>
  58. <p><strong>MIME types defined:</strong> <code>text/x-swift</code> (Swift code)</p>
  59. </article>