swift手记-3

前端之家收集整理的这篇文章主要介绍了swift手记-3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

//
//  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()
    }
}

堆栈算法

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

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


}

原文链接:https://www.f2er.com/swift/324816.html

猜你在找的Swift相关文章