swift代码执行的入口点是什么? [英] What is the entry point of swift code execution?

查看:38
本文介绍了swift代码执行的入口点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

swift 中没有 main() 方法.程序必须从某处开始执行.那么swift代码执行的入口点是什么,又是如何决定的呢?

There is no main() method in swift. The program must start the execution from somewhere. So what is the entry point of swift code execution and how is it decided?

推荐答案

普通 Swift 模块的入口点是模块中名为 main.swift 的文件.main.swift 是唯一允许在顶层包含表达式和语句的文件(模块中的所有其他 Swift 文件只能包含声明).

The entry point in a plain Swift module is the file in the module called main.swift. main.swift is the only file which is allowed to have expressions and statements at the top level (all other Swift files in the module can only contain declarations).

Cocoa Touch 使用 @UIApplicationMain 属性关于UIApplicationDelegate 而不是 main.swift 文件来标记入口点.Cocoa 过去使用一个最小的 main.swift 文件,它简单地调用了 NSApplicationMain,但是 自 Xcode 6.1 起 使用 @NSApplicationMain 属性关于 NSApplicationDelegate 的实现.

Cocoa Touch uses the @UIApplicationMain attribute on an implementation of UIApplicationDelegate instead of a main.swift file to mark the entry point. Cocoa used to use a minimal main.swift file which simply called NSApplicationMain, but as of Xcode 6.1 uses the @NSApplicationMain attribute on an implementation of NSApplicationDelegate.

这篇关于swift代码执行的入口点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆