Swift 类方法 和OC类似,就是通过类本身调用方法,在方法(func)关键字前面用static修饰,如果父类允许子类重载方法,就用关键字class修饰
import UIKit
import Foundation
class MsgToolBox: NSObject {
static public func showAlert(title: String, content: String) -> () {
//保证在主线程上执行
if Thread.isMainThread == true {
let alertView = UIAlertView.init(title: title, message: content, delegate: self, cancelButtonTitle: "已阅")
alertView.show()
} else {
DispatchQueue.main.async {
let alertView = UIAlertView.init(title: title, message: content, delegate: self, cancelButtonTitle: "已阅")
alertView.show()
}
}
}
}
//调用
MsgToolBox.showAlert(title: "温馨提示", content: "请输入标签!")