简体   繁体   English

Swift编程语言的语法

[英]Syntax of Swift programming language

When i was trying to implement one of the protocol, i came across the following syntax. 当我尝试实现一种协议时,遇到了以下语法。

optional public func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?)

Can anyone explain the meaning of the "didFinishWithResult"? 谁能解释“ didFinishWithResult”的含义? Is it a argument? 是争论吗? If not what is it? 如果不是,那是什么?

didFinishWithResult is the external parameter name. didFinishWithResult是外部参数名称。 result is the internal one. result是内部的。 So, when you call the method, the external is used and within the method the internal is used. 因此,当您调用方法时,将使用外部方法,而在方法内部则使用内部方法。

In Objective C the method is defined as follows with parameter names: 在Objective C中,该方法使用参数名称定义如下:

- (void)mailComposeController:(MFMailComposeViewController *)controller
      didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error

When you translate it to swift you can declare external and internal parameters 将其转换为快速内容时,可以声明外部和内部参数

Function parameters have both an external parameter name and a local parameter name. 函数参数同时具有外部参数名称和本地参数名称。 An external parameter name is used to label arguments passed to a function call. 外部参数名称用于标记传递给函数调用的参数。 A local parameter name is used in the implementation of the function. 函数的实现中使用本地参数名称。

By default, the first parameter omits its external name, and the second and subsequent parameters use their local name as their external name. 默认情况下,第一个参数省略其外部名称,第二个及后续参数使用其本地名称作为其外部名称。 All parameters must have unique local names. 所有参数必须具有唯一的本地名称。 Although it's possible for multiple parameters to have the same external name, unique external names help make your code more readable. 尽管多个参数可能具有相同的外部名称,但是唯一的外部名称有助于使代码更具可读性。

You write an external parameter name before the local parameter name it supports, separated by a space: 您在外部参数名称支持的外部参数名称之前写入一个外部参数名称,并用空格分隔:

func someFunction(externalParameterName localParameterName: Int) {
    // function body goes here, and can use localParameterName
    // to refer to the argument value for that parameter
}

Source https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html 来源https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM