访问 AppDelegate 的代码究竟是做什么的?

时间:2021-03-13 03:17:00

标签: ios swift swift5

我很好奇下面这行代码到底做了什么,以及为什么使用这个特定的语法来引用 AppDelegate。

(UIApplication.shared.delegate as! AppDelegate).method_or_variable_name

另外,这个语法与这些语法有什么不同?

AppDelegate().whatever_method_that_is_in_AppDelegate
AppDelegate.whatever_variable_of_App_Delegate

当我使用 Swift 进行开发时,我发现无论何时访问脚本的变量,我都应该使用 StructName.variable 语法,而无论何时访问脚本的方法,我都应该使用 StructName().method 语法。我仍然是 Swift 的初学者,所以我有一种强烈的感觉,我没有使用“Swifty”实践。

我希望得到一些见解。

0 个答案:

没有答案