Swift 中的“@"符号是什么意思? [英] What does the '@' symbol mean in Swift?

查看:58
本文介绍了Swift 中的“@"符号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目标 C 方面没有经验,所以我在一些符号上遇到了问题.在我的AppDelegate.swift"文件中,顶部有一个@UIMainApplication".这是什么意思?

I have no experience in objective C, so I'm having trouble with some of the notation. In my "AppDelegate.swift" file, there is a "@UIMainApplication" at the top. What does this mean?

另外,如果可能的话,请给我 C++ 中的等效"语句(如果存在)?

Also, if possible, could you please give me the "equivalent" statement (if it exists) in C++?

谢谢.

推荐答案

好吧,您选择了一个相当复杂的方案.@ 仅仅意味着这是一个属性 - 一个特殊的标记或编译器的信号,如 Apple 在这里解释.但是@UIApplicationMain 是一个特别深刻的属性!它替代了位于 main.m 文件(如 我在这里解释):

Well, you picked a rather complicated one. The @ merely means that this is an attribute - a special marker or signal to the compiler, as Apple explains here. But @UIApplicationMain is a particularly profound attribute! It substitutes for the entire UIApplicationMain implementation that lies at the heart of a C / Objective-C application, in the main.m file (as I explain here):

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil,
                                 NSStringFromClass([AppDelegate class]));
    }
}

这是应用程序的主要入口点,实现整个启动和运行代码,正在运行的应用程序.你可以在 Swift 中做类似的事情——一个 main.swift 文件和 Swift 等价的代码——但是 Swift 通过让你指定你的应用程序委托类来为你省去麻烦使用 @UIApplicationMain 属性.

That is the main entry point of the app, implementing the entire launch-and-run code that is the running application. You can do something like that in Swift — a main.swift file with the Swift equivalent of that code — but Swift saves you the trouble by letting you designate your app delegate class with the @UIApplicationMain attribute.

如果您将项目作为 Objective-C 或 Objective-C++ 项目启动,模板将为您提供一个包含 main 实现的 main 文件,因此无需在这方面做任何特别的事情.

If you start a project as an Objective-C or Objective-C++ project, the template will give you a main file containing the main implementation, so there's no need to do anything special in this regard.

这篇关于Swift 中的“@"符号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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