2、该部分如不够填写,请另加附页)l代码:ViewController.swift:// ViewController.swift// text7//// Created by wu on 2017/11/9.// Copyright 2017年 2015110445. All rights reserved.//import Cocoaclass ViewController: NSViewController { @IBOutlet weak var display: NSTextFieldCell! //显示值的文本框 var isUerTyping
3、= false //判断用户是否正在输入 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. //更改窗口背景图片 let image = NSImage(named: "timg") let imageView = NSImageView(image: image!) imageView.frame = self.view.bou
4、nds self.view.addSubview(imageView, positioned: NSWindowOrderingMode.below, relativeTo: self.view) //设置文本框不可编辑 display.isEditable = false } //输入值(数组按钮和.按钮) @IBAction func setValue(_ sender: NSButton) { if isUerTyping { let title = sender.ti
5、tle if title != "."
6、
7、 !display.title.contains(".") { display.title += title } } else { display.title = sender.title isUerTyping = true } } //文本框中的显示值 var displayValue: Double { get { return Doubl
8、e(display.title)! } set { display.title = String(newValue) } } //实例化一个计算器的模型 private var operat = Operation() //进行计算(特殊字符按钮) @IBAction func operation(_ sender: NSButton) { //先将文本框中的内容保存到结构体实例中 if isUerTyping { operat
9、.setOperand(operand: displayValue) isUerTyping = false } //再进行计算 operat.performCalculation(symbol: sender.title) //最后显示结果 if let result =