加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 05:38:49 所属栏目:百科 来源:网络整理
导读:根据 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 implementatio
根据 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))
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读