微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/swift/318634.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐