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

前端之家收集整理的这篇文章主要介绍了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))
}
原文链接:https://www.f2er.com/swift/318634.html

猜你在找的Swift相关文章