AppDelegate.swift如何在Xcode 6.3中替换AppDelegate.h和AppDelegate.m

根据 iOS Developer Library

The app delegate is where you write your custom app-level code. Like all classes,the AppDelegate class is defined in two source code files in your app: in the interface file,AppDelegate.h,and in the implementation file,AppDelegate.m.

但是,在Xcode 6.3中,似乎只有AppDelegate.swift,而不再是.h和.m扩展名.我想了解.swift如何替换.h和.m扩展名.

简单的答案是AppDelegate.swift只是Objective-C AppDelegate.h和AppDelegate.m的转换,因为Swift不需要单独的头文件和实现,而是单个.swift文件.

然而,在引擎盖下,两者之间还存在其他关键差异.

在Objective-C中,存在一个main.m文件,其唯一目的是实例化UIApplicationMain

在Swift中,位于AppDelegate.swift顶部的@UIApplicationMain注释标记取代了Objective-C中main.m文件中存在的任何main函数的需要.如果省略此标记,则可以使用main.swift文件使用指定的App Delegate实例化UIApplication.

main.swift实现如下所示:

import UIKit

autoreleasepool {
UIApplicationMain(Process.argc,Process.unsafeArgv,nil,NsstringFromClass(AppDelegate.self))
}

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...