The Swift Code主要是通过编写代码来完成应用程序的实现,使我们更能够深入的了解其编程语言实现的原理.也能够辅助更快的使用XCODE开发应用程序.
这篇文章主要是讲解启动应用程序从代码入口.
其实这里主要是通过注解来实现的,新建IOS swift项目的时候,会生成一个AppDelegate文件,这个文件就是应用程序的代码入口,在声明类的同时加入了注解@UIApplicationMain,表明这个应用程序.其实在这之前,我们必须在配置文件里设置启动入口为Main
650) this.wIDth=650;" alt="4801DAAE-B3CF-4446-B37D-97761FC4D9BC.png" src="http://img.jb51.cc/vcimg/static/loading.png" title="1427448279408064751.png" src="http://www.wutongwei.com/ueditor/Jsp/upload/image/20150327/1427448279408064751.png">
以下讲解,我们在代码里做讲解,大家可以试试在模拟里调试
importUIKit@UIApplicationMainclassAppDelegate:UIResponder,UIApplicationDelegate{varwindow:UIWindow?/*程序未启动时,点击应用程序触发该方法,之后触发applicationDIDBecomeActive*/funcapplication(application:UIApplication,dIDFinishLaunchingWithOptionslaunchOptions:[NSObject:AnyObject]?)->Bool{//OverrIDepointforcustomizationafterapplicationlaunch.NSLog("开始启动application........")window=UIWindow(frame:UIScreen.mainScreen().bounds)window?.backgroundcolor=UIcolor.orangecolor()window?.rootVIEwController=VIEwController()returntrue}/*点击HOme键后,程序即将进入委托处理(委托给系统处理),紧跟着将会触发applicationDIDEnterBackground方法*/funcapplicationWillResignActive(application:UIApplication){//Sentwhentheapplicationisabouttomovefromactivetoinactivestate.Thiscanoccurforcertaintypesoftemporaryinterruptions(suchasanincomingphonecallorSMSmessage)orwhentheuserquitstheapplicationanditbeginstheTransitiontothebackgroundstate.//UsethismethodtopauSEOngoingtasks,disabletimers,andthrottledownopenGLESframerates.Gamesshouldusethismethodtopausethegame.NSLog("开始启动applicationWillResignActive........")}/*用户点击了Home按键,程序进入后台处理*/funcapplicationDIDEnterBackground(application:UIApplication){//Usethismethodtoreleasesharedresources,saveuserdata,invalIDatetimers,andstoreenoughapplicationstateinformationtorestoreyourapplicationtoitscurrentstateincaseitisterminatedlater.//Ifyourapplicationsupportsbackgroundexecution,thismethodiscalledinsteadofapplicationWillTerminate:whentheuserquits.NSLog("开始启动applicationDIDEnterBackground........")}/*在应用程序未消亡状态,状态由后台处理,进入前台处理,触发该方法,之后触发applicationDIDBecomeActive*/funcapplicationWillEnterForeground(application:UIApplication){//CalledaspartoftheTransitionfromthebackgroundtotheinactivestate;hereyoucanundomanyofthechangesmadeonenteringthebackground.NSLog("开始启动applicationWillEnterForeground........")}/*应用程序进入后,触发该方法*/funcapplicationDIDBecomeActive(application:UIApplication){//Restartanytasksthatwerepaused(ornotyetstarted)whiletheapplicationwasinactive.IftheapplicationwasprevIoUslyinthebackground,optionallyrefreshtheuserinterface.NSLog("开始启动applicationDIDBecomeActive........")}funcapplicationWillTerminate(application:UIApplication){//CalleDWhentheapplicationisabouttoterminate.Savedataifappropriate.SeealsoapplicationDIDEnterBackground:.NSLog("开始启动applicationWillTerminate........")}}
转载至吴统威的博客:http://www.wutongwei.com/front/infor_showone.tweb?ID=87
总结以上是内存溢出为你收集整理的The Swift Code之应用程序的启动过程全部内容,希望文章能够帮你解决The Swift Code之应用程序的启动过程所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)