@UIApplicationMain与main()的种种关系

2019-02-15  本文已影响9人  super大太阳

当你从oc项目转到swift项目的时候你会发现main.m文件怎么没了?!是不是出错了?是不是需要我自己去配置?答案是否定的

机智.jpeg

Object-c

C 系列语言中,程序的入口都是 main 函数,一个 Objective-C 的 iOS app 项目在新建时,Xcode 会给我们创建好一个 main.m 的文件。

swift

官方文档已经给出答案啦
In Xcode, Mac templates default to including a “main.swift” file, but for iOS apps the default for new iOS project templates is to add @UIApplicationMain to a regular Swift file. This causes the compiler to synthesize a mainentry point for your iOS app, and eliminates the need for a “main.swift” file.

在Xcode中,Mac模板默认包含“main”。但是对于iOS应用程序,新iOS项目模板的默认设置是将@UIApplicationMain添加到常规的swift文件中。这将导致编译器为您的iOS应用程序合成一个主入口点,并消除对“main.swift”文件的需要。

这也是我自己在写swift项目的时候遇到的问题,并且记录了下来,好记性不如烂笔头

上一篇 下一篇

猜你喜欢

热点阅读