AppDelegate.swift如何在Xcode 6.3中替换AppDelegate.h和AppDelegate.m [英] How does AppDelegate.swift replace AppDelegate.h and AppDelegate.m in Xcode 6.3
问题描述
根据 iOS开发人员库 >
应用程序委托是您编写自定义应用程序级代码的地方.与所有类一样,AppDelegate类在应用程序的两个源代码文件中定义:在接口文件AppDelegate.h和在实现文件AppDelegate.m中.
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扩展名.
However, in Xcode 6.3 it appears that there is only AppDelegate.swift and no longer the .h and .m extensions. I would like to understand how the .swift replaced both the .h and .m extensions.
推荐答案
简单的答案是AppDelegate.swift只是Objective-C AppDelegate.h
和AppDelegate.m
的翻译,因为Swift不需要单独的标头和实现,而是一个.swift文件.
The simple answer is that AppDelegate.swift is just the translation from Objective-C AppDelegate.h
and AppDelegate.m
, as Swift does not require separate headers and implementations, but rather a single .swift file.
但是,在内部,两者之间还有其他关键区别.
However, under the hood, there are other key differences between the two.
在Objective-C中,存在一个main.m
文件,其唯一目的是实例化UIApplicationMain
In Objective-C, there exists a main.m
file that's sole purpose is instantiating UIApplicationMain
在Swift中,位于AppDelegate.swift顶部的@UIApplicationMain
注释标记取代了对Objective-C中main.m文件中存在的任何主要功能的需求.如果省略此标签,则可以使用main.swift文件使用指定的App Delegate实例化UIApplication
.
In Swift, the @UIApplicationMain
annotation tag found at the top of AppDelegate.swift replaces the need for any main function that existed in the main.m file in Objective-C. If this tag is omitted, you can use a main.swift file to instantiate your UIApplication
using the specified App Delegate.
main.swift实现如下:
A main.swift implementation looks like this:
import UIKit
autoreleasepool {
UIApplicationMain(Process.argc, Process.unsafeArgv, nil, NSStringFromClass(AppDelegate.self))
}
这篇关于AppDelegate.swift如何在Xcode 6.3中替换AppDelegate.h和AppDelegate.m的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!