swift手记-4

前端之家收集整理的这篇文章主要介绍了swift手记-4前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. //
  2. // ViewController.swift
  3. // learn4
  4. //
  5. // Created by myhaspl on 16/1/23.
  6. // Copyright (c) 2016年 myhaspl. All rights reserved.
  7. //
  8.  
  9. import Cocoa
  10.  
  11. class ViewController: NSViewController {
  12. var fifoquene=[Int]()
  13. var lifoquene=[Int]()
  14.  
  15. override func viewDidLoad() {
  16. super.viewDidLoad()
  17.  
  18. // Do any additional setup after loading the view.
  19. }
  20.  
  21. override var representedObject: AnyObject? {
  22. didSet {
  23. // Update the view,if already loaded.
  24. }
  25. }
  26. @IBOutlet weak var inputnum1: NSTextField!
  27. @IBOutlet weak var inputnum2: NSTextField!
  28. @IBOutlet weak var fifostate: NSTextField!
  29. @IBOutlet weak var lifostate: NSTextField!
  30. @IBAction func lifopop(sender: AnyObject) {
  31. let messageBox:NSAlert=NSAlert()
  32. if lifoquene.count>0{
  33. let mynum=lifoquene.removeLast()
  34. lifostate.stringValue="后进先出"+" "
  35. for num in lifoquene{
  36. lifostate.stringValue=lifostate.stringValue+String(num)+" "
  37. }
  38. messageBox.messageText="您取出了"+String(mynum)
  39. }
  40. else{
  41. messageBox.messageText="队列为空"
  42. }
  43. messageBox.alertStyle=NSAlertStyle.InformationalAlertStyle
  44. messageBox.runModal()
  45. }
  46. @IBAction func lifopush(sender: AnyObject) {
  47. if let mynum=inputnum2.stringValue.toInt(){
  48. lifoquene.append(mynum)
  49. lifostate.stringValue+=" "+String(mynum)
  50. }
  51. }
  52. @IBAction func fifopop(sender: AnyObject) {
  53. let messageBox:NSAlert=NSAlert()
  54. if fifoquene.count>0{
  55. let mynum=fifoquene.removeAtIndex(0)
  56. fifostate.stringValue="先进先出"+" "
  57. for num in fifoquene{
  58. fifostate.stringValue=fifostate.stringValue+String(num)+" "
  59. }
  60. messageBox.messageText="您取出了"+String(mynum)
  61. }
  62. else{
  63. messageBox.messageText="队列为空"
  64. }
  65. messageBox.alertStyle=NSAlertStyle.InformationalAlertStyle
  66. messageBox.runModal()
  67. }
  68. @IBAction func fifopush(sender: AnyObject) {
  69. if let mynum=inputnum1.stringValue.toInt(){
  70. fifoquene.append(mynum)
  71. fifostate.stringValue+=" "+String(mynum)
  72. }
  73. }
  74. }

博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/


猜你在找的Swift相关文章