Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么在参数的参数中使用(点)?_Ios_Swift - Fatal编程技术网

Ios 为什么在参数的参数中使用(点)?

Ios 为什么在参数的参数中使用(点)?,ios,swift,Ios,Swift,目前正在努力学习swift,我有点困惑,为什么有些论点前面有点,而有些则没有。比如说 向UIAlertView对象添加按钮的步骤 警报名称=simplelert 按钮标题=“是” 按钮的样式=默认值 handler=nil 为什么写这篇文章的合适方式是 simpleAlert.addAction(UIAlertAction(title:"YES",style: .Default, handler: nil)) 而不是 simpleAlert.addAction(UIAlertAction(ti

目前正在努力学习swift,我有点困惑,为什么有些论点前面有点,而有些则没有。比如说

向UIAlertView对象添加按钮的步骤

警报名称=simplelert

按钮标题=“是”

按钮的样式=默认值

handler=nil

为什么写这篇文章的合适方式是

simpleAlert.addAction(UIAlertAction(title:"YES",style: .Default, handler: nil))
而不是

simpleAlert.addAction(UIAlertAction(title:"YES",style: Default, handler: nil))

这是编写
UIAlertActionStyle.Default
UIAlertActionStyle
是一个枚举,
Default
是它的一个值)。
UIAlertView
已经知道您将对该参数使用
UIAlertActionStyle
,这样您就可以直接写入该枚举的值。

这是写入
UIAlertActionStyle.Default
的一种简单方法(
UIAlertActionStyle
是一个枚举,而
Default
是它的一个值)。
UIAlertView
已经知道您将对该参数使用
UIAlertActionStyle
,这样您就可以直接写入该枚举的值

simpleAlert.addAction(UIAlertAction(title:"YES",style: .Default, handler: nil))
也可以写成

 simpleAlert.addAction(UIAlertAction(title:"YES",style: UIAlertActionStyle.Default
, handler: nil))
UIAlertActionStyle是枚举

enum UIAlertActionStyle : Int {

    case Default
    case Cancel
    case Destructive
}
因此,默认值只是一种简化,这意味着枚举类型已经给定,我们只需传递我们想要使用的适当大小写即可

也可以写成

 simpleAlert.addAction(UIAlertAction(title:"YES",style: UIAlertActionStyle.Default
, handler: nil))
UIAlertActionStyle是枚举

enum UIAlertActionStyle : Int {

    case Default
    case Cancel
    case Destructive
}

因此.Default只是一种简化,这意味着已经给出了枚举类型,我们只需传递我们想要使用的适当大小写。

正如其他人所说,这是UIAlertActionStyle.Default的缩写

跳过枚举的名称,只列出值(
.Default
而不是
UIAlertActionStyle.Default
)就是Swift“类型推断”的一个示例


类型推断意味着,如果编译器可以推断(计算)某个值/参数的类型,则不必显式地声明它。在上面的示例中,您为
style
提供的值必须是UIAlertActionStyle类型的值,因此您可以跳过该部分。

正如其他人所说,这是UIAlertActionStyle.Default的缩写

跳过枚举的名称,只列出值(
.Default
而不是
UIAlertActionStyle.Default
)就是Swift“类型推断”的一个示例

类型推断意味着,如果编译器可以推断(计算)某个值/参数的类型,则不必显式地声明它。在上面的示例中,为
style
提供的值必须是UIAlertActionStyle类型的值,因此可以跳过该部分