Swift 類方法 和OC類似,就是通過類本身調(diào)用方法,在方法(func)關(guān)鍵字前面用static修飾,如果父類允許子類重載方法,就用關(guān)鍵字class修飾
import UIKit
import Foundation
class MsgToolBox: NSObject {
static public func showAlert(title: String, content: String) -> () {
//保證在主線程上執(zhí)行
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()
}
}
}
}
//調(diào)用
MsgToolBox.showAlert(title: "溫馨提示", content: "請輸入標簽!")