在SDK中有打印日志的公共方法,需要将打印的内容透传给外部APP调用,使APP可以自由拦截日志打印,从而可以根据APP的需要使用日志调试工具。
open class TempLogClass {
static let `default` = TempLogClass()
open func logAction(_ message: String, time: String, file: String, level: Int) -> Bool {
return false
}
}
open override func logAction(_ message: String, time: String, file: String, level: Int) -> Bool {
MBProgressHUD.log("\(time): \(file)-->\(message)")
return true
}
提示:Method does not override any method from its superclass
open class SuperLog {
@available(iOS 13.0.0, *)
@objc dynamic open func logAction(_ message: String, time: String, file: String, level: Int) -> Bool {
return false
}
}
open class TempLogClass: SuperLog {
static let `default` = TempLogClass()
}
extension TempLogClass {
@available(iOS 13.0.0, *)
@objc dynamic open override func logAction(_ message: String, time: String, file: String, level: Int) -> Bool {
MBProgressHUD.log("\(time): \(file)-->\(message)")
return true
}
}
动态派发机制 需要@objc dynamic
入口+动态派发机制
这时调用DKTempLogClass.default.dklogAction("\(message)", time: time, file: fileName, level: 0)
,
就会执行分类中的方法。