启动时间影响
cleven1 opened this issue · 1 comments
// 1. 定义 WRAwakeProtocol 协议
public protocol WRAwakeProtocol: class {
static func wrAwake()
}
public protocol WRFatherAwakeProtocol: class
{ // 1.1 定义 WRFatherAwakeProtocol ()
static func fatherAwake()
}
class NothingToSeeHere
{
static func harmlessFunction(){
let typeCount = Int(objc_getClassList(nil, 0))
let types = UnsafeMutablePointer<AnyClass?>.allocate(capacity: typeCount)
let autoreleaseintTypes = AutoreleasingUnsafeMutablePointer(types)
objc_getClassList(autoreleaseintTypes, Int32(typeCount)) //获取所有的类
for index in 0 ..< typeCount {
(types[index] as? WRAwakeProtocol.Type)?.wrAwake() //如果该类实现了SelfAware协议,那么调用 awake 方法
(types[index] as? WRFatherAwakeProtocol.Type)?.fatherAwake()
}
types.deallocate(capacity: typeCount)
}
}
// 2. 让APP启动时只执行一次 harmlessFunction 方法
extension UIApplication
{
private static let runOnce:Void = { //使用静态属性以保证只调用一次(该属性是个方法)
NothingToSeeHere.harmlessFunction()
}()
open override var next: UIResponder?{ //重写next属性
UIApplication.runOnce
return super.next
}
}
这段代码,会增加APP的启动时间,严重影响了APP启动时间
之前改了忘记提交了,你现在看看