// // ViewController.swift // learn3 // // Created by myhaspl on 16/1/23. // Copyright (c) 2016年 myhaspl. All rights reserved. // import Cocoa class ViewController: NSViewController { var mystatck:[Int32]=[] override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override var representedObject: AnyObject? { didSet { // Update the view, if already loaded. } } @IBOutlet weak var inputnum: NSTextField! @IBOutlet weak var stackstate: NSTextField! @IBAction func pushNumber(sender: AnyObject) { mystatck.append(inputnum.intValue) stackstate.stringValue="堆栈情况" for mynum in mystatck{ stackstate.stringValue+=String(mynum)+" " } } @IBAction func popNumber(sender: AnyObject) { let messagebox:NSAlert=NSAlert() if mystatck.count>0{ let removed = mystatck.removeLast() stackstate.stringValue="堆栈情况" for mynum in mystatck{ stackstate.stringValue+=String(mynum)+" " } messagebox.messageText="您取出了"+String(removed) } else{ messagebox.messageText="堆栈为空" } messagebox.alertStyle=NSAlertStyle.InformationalAlertStyle messagebox.runModal() } }
}