Swift-@UIApplicationMain
发布时间:2020-12-14 06:55:38 所属栏目:百科 来源:网络整理
导读:Swift-@UIApplicationMain 感谢喵神的《100个Swift开发必备 Tip》内容参考自 “Tip43 @UIApplicationMain” 在C系语言中,程序的入口都是 main 函数,对于熟悉的OC APP项目,Xcode自动帮我们新建了一个 main.m 文件,其中就有main函数: int main( int argc,
Swift-@UIApplicationMain感谢喵神的《100个Swift开发必备 Tip》内容参考自 “Tip43 @UIApplicationMain”
int main(int argc,char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc,argv,nil,NSStringFromClass([AppDelegate class]));
}
}
====================== 分割线 ===================
@UIApplicationMain
Undefined symbols for architecture x86_64:
"_main",referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
* 意思应该是找不到main函数
import UIKit
class MyApplication: UIApplication { } UIApplicationMain(Process.argc,Process.unsafeArgv,nil,NSStringFromClass(AppDelegate))
'UIApplicationMain' attribute cannot be used in a module that contains top-level code
* 可以全局监听事件*
/// This function is called in the main entry point to create the application object and the application delegate and set up the event cycle. Even though an integer return type is specified,this function never returns. When users exits an iOS application by pressing the Home button,the application moves to the background.
///
/// @param argc The count of arguments in argv; this usually is the corresponding parameter to main.
/// @param argv A variable list of arguments; this usually is the corresponding parameter to main.
/// @param principalClassName The name of the UIApplication class or subclass. If you specify nil,UIApplication is assumed.
/// @param delegateClassName designates a subclass of UIApplication,you may designate the subclass as the delegate; the subclass instance receives the application-delegate messages. Specify nil if you load the delegate object from your application’s main nib file.
///
/// @return Even though an integer return type is specified,this function never returns.
public func UIApplicationMain(argc: Int32,_ argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>>,_ principalClassName: String?,_ delegateClassName: String?) -> Int32
import UIKit
class MyApplication: UIApplication {
override func sendEvent(event: UIEvent) {
super.sendEvent(event)
print("sendEvent")
}
}
// 第三个参数不要传nil
UIApplicationMain(Process.argc,Process.unsafeArgv,NSStringFromClass(MyApplication),NSStringFromClass(AppDelegate))
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |