Macos 如何使用swift在mac中制作警报控制器

Macos 如何使用swift在mac中制作警报控制器,macos,cocoa,appkit,Macos,Cocoa,Appkit,我是Swift新手,我正在尝试为MacOSX制作一个计分收集程序。我确实知道iOS上的Swift编程,但我对OSXSIFT了解不多。所以我为OSX写了一个程序。我几乎完成了它,但我想知道如何使用swift在mac上制作警报控制器。我知道如何在iso上做,但我不知道如何在OSX上做,我也想知道如何使用 OSX 导入可可粉 类ViewController:NSViewController{ @IBMOutlet变量数学:NSTextField!=NSTextField() @ibvar科学:NSTe

我是Swift新手,我正在尝试为MacOSX制作一个计分收集程序。我确实知道iOS上的Swift编程,但我对OSXSIFT了解不多。所以我为OSX写了一个程序。我几乎完成了它,但我想知道如何使用swift在mac上制作警报控制器。我知道如何在iso上做,但我不知道如何在OSX上做,我也想知道如何使用 OSX

导入可可粉
类ViewController:NSViewController{
@IBMOutlet变量数学:NSTextField!=NSTextField()
@ibvar科学:NSTextField!=NSTextField()
@IBOutlet var English:NSTextField!=NSTextField()
@ibc:NSTextField!=NSTextField()
@IBOutlet变量历史记录:NSTextField!=NSTextField()
@IBVAR地理位置:NSTextField!=NSTextField()
@ibextfield:NSTextField!=NSTextField()
@IBOutlet var计算:NSTextField!=NSTextField()
@IBOUTLE var总计:NSTextField!
@IBOUTLE var AVG:NSTextField!
@IBVAR学生名:NSTextField!
@IBVAR学生类:NSTextField!
@IBOUTLE var报告:NSTextField!
重写func viewDidLoad(){
super.viewDidLoad()
}
覆盖var representedObject:AnyObject{
迪塞特{
//更新视图(如果已加载)。
}
}
@iAction func CountTotalnAVG(发送方:NSButton){
var Mathsc=math.stringValue.toInt()
var Sciencec=Science.stringValue.toInt()
var Englishc=English.stringValue.toInt()
var Religiousc=religal.stringValue.toInt()
var Historyc=History.stringValue.toInt()
var Geographyc=Geography.stringValue.toInt()
var ICTc=ICT.stringValue.toInt()
var computingc=Computing.stringValue.toInt()
/*
变量加=(数学?.advancedBy(科学!).advancedBy(英语!).advancedBy(宗教!).advancedBy(历史!).advancedBy(地理!).advancedBy(ICTc!).advancedBy(计算!))
*/
变量add:Int=(数学!+科学!+英语!+宗教!+历史!+地理!+ICTc!+计算!)
如果(数学!==“”){
}
否则{
Total.stringValue=“\(添加)”
var divide:Int=add/8
AVG.stringValue=“\(除法)”
}
}
@iAction func GetReport(发件人:NSButton){
var Mathsc=math.stringValue.toInt()
var Sciencec=Science.stringValue.toInt()
var Englishc=English.stringValue.toInt()
var Religiousc=religal.stringValue.toInt()
var Historyc=History.stringValue.toInt()
var Geographyc=Geography.stringValue.toInt()
var ICTc=ICT.stringValue.toInt()
var computingc=Computing.stringValue.toInt()
func getGrade(分数:Int)->字符串{
让结果:字符串
交换分数{
案例80…100:
结果=“A”

案例75.与UIAlertController相关的iOS或macOS之间没有差异

    let title = "Do you want to save the changes made to the document?".localized
    let description = "Your changes will be lost if you don’t save them.".localized
    
    let discard = "Don't Save".localized
    let save = "Save".localized
    let cancel = "Cancel".localized
    
    let alert = UIAlertController(title: title, message: description, preferredStyle: .alert)
    let discardAction = UIAlertAction(title: discard, style: .destructive) { _ in
        // don't save action here
    }
    let saveAction = UIAlertAction(title: save, style: .default) { _ in
        // save action here
    }
    let cancelAction = UIAlertAction(title: cancel, style: .cancel) { _ in }
    
    alert.addAction(discardAction)
    alert.addAction(cancelAction)
    alert.addAction(saveAction)

    yourViewController.present(alert, animated: true, completion: nil)

根据您看到的显示内容,对于macOS目标,不存在半类似于
UIAlertView
UIAlertController
的签出
NSAlert
    let title = "Do you want to save the changes made to the document?".localized
    let description = "Your changes will be lost if you don’t save them.".localized
    
    let discard = "Don't Save".localized
    let save = "Save".localized
    let cancel = "Cancel".localized
    
    let alert = UIAlertController(title: title, message: description, preferredStyle: .alert)
    let discardAction = UIAlertAction(title: discard, style: .destructive) { _ in
        // don't save action here
    }
    let saveAction = UIAlertAction(title: save, style: .default) { _ in
        // save action here
    }
    let cancelAction = UIAlertAction(title: cancel, style: .cancel) { _ in }
    
    alert.addAction(discardAction)
    alert.addAction(cancelAction)
    alert.addAction(saveAction)

    yourViewController.present(alert, animated: true, completion: nil)