原文:http://stackoverflow.com/questions/24020000/subclass-uiapplication-with-swift
1.首先定義UIApplication的子類SLApplication
import Foundation
import UIKit
class SLApplication: UIApplication {
override func sendEvent(event: UIEvent) {
super.sendEvent(event)
print("send event")
}
}
2.設(shè)置入口
新建main.swift店煞,
import Foundation
import UIKit
UIApplicationMain(Process.argc, Process.unsafeArgv, NSStringFromClass(SLApplication), NSStringFromClass(AppDelegate))
3、去掉Appdelegate的@UIApplicationMain
@UIApplicationMain
在類的最頂部聲明@UIApplicationMain,表示該類是application的delegate。如果不用該屬性標(biāo)識(shí),另外一種做法是在main.swift中調(diào)用UIApplicationMain函數(shù),設(shè)置delegate和application竹伸。以上我們就是根據(jù)這種方法來(lái)設(shè)置的。
Apply this attribute to a class to indicate that it is the application delegate. Using this attribute is equivalent to calling the UIApplicationMain function and passing this class’s name as the name of the delegate class.
If you do not use this attribute, supply a main.swift file with a main function that calls the UIApplicationMain(:::) function. For example, if your app uses a custom subclass of UIApplication
as its principal class, call the UIApplicationMain(:::) function instead of using this attribute.