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

查看:308
本文介绍了什么是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?

推荐答案

模块中的文件名为 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 属性。 com / library / ios / documentation / UIKit / Reference / UIApplicationDelegate_Protocol / index.html> UIApplicationDelegate 而不是 main.swift 文件来标记入口点。 Cocoa曾经使用最少的 main.swift 文件,只是简单地调用 NSApplicationMain ,但的Xcode 6.1 使用 <$ @NSApplicationMain 属性 .html> 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天全站免登陆