Swift 指定类似“的属性”之间的区别;UIAlertActionStyle.Default";vs";。默认值;?

Swift 指定类似“的属性”之间的区别;UIAlertActionStyle.Default";vs";。默认值;?,swift,Swift,我是Swift的初学者,不知道如何用谷歌搜索。我知道,在Swift中指定属性时,可以执行以下任一操作: UIAlertAction(标题:“确定”,样式:UIAlertActionStyle.Default) 或 UIAlertAction(标题:“确定”,样式:。默认值) 是否有一种方法可以引用指定属性的每种方法,以及在行为上是否有任何差异?这是一个快速的事情还是一个iOS特有的事情?链接到文档也会有所帮助。提前感谢。首先UIAlertActionStyle.Default已更改为UIAl

我是Swift的初学者,不知道如何用谷歌搜索。我知道,在Swift中指定属性时,可以执行以下任一操作:

UIAlertAction(标题:“确定”,样式:UIAlertActionStyle.Default)

UIAlertAction(标题:“确定”,样式:。默认值)

是否有一种方法可以引用指定属性的每种方法,以及在行为上是否有任何差异?这是一个快速的事情还是一个iOS特有的事情?链接到文档也会有所帮助。提前感谢。

首先
UIAlertActionStyle.Default
已更改为
UIAlertAction.Style.Default

这是斯威夫特特有的,写作和写作没有区别

UIAlertAction (title: "OK", style: UIAlertAction.Style.default)

这是编写第二个方法的快捷方式

以枚举为例:

enum MyEnum {
   case first, second
}
如果我们想进行如下比较:

let myEnum: MyEnum = .first

if myEnum == .first {
   // Action
}
它的可读性比:

let myEnum = MyEnum.first

if myEnum == MyEnum.first {
   // Action
}

第一个
UIAlertActionStyle.Default
已更改为
UIAlertAction.Style.Default

这是斯威夫特特有的,写作和写作没有区别

UIAlertAction (title: "OK", style: UIAlertAction.Style.default)

这是编写第二个方法的快捷方式

以枚举为例:

enum MyEnum {
   case first, second
}
如果我们想进行如下比较:

let myEnum: MyEnum = .first

if myEnum == .first {
   // Action
}
它的可读性比:

let myEnum = MyEnum.first

if myEnum == MyEnum.first {
   // Action
}

我明白了,谢谢你的解释!我知道这是一个基本问题,但Swift如何推断
.default
意味着
UIAlertActionStyle.default
?是因为
UIAlertAction
style
必须是
UIAlertActionStyle
?因为函数的参数是UIAlertActionStyle类型,所以swift知道您不能再放一个类型。我明白了,谢谢。文档告诉我,
UIAlertAction.Style
是一个枚举-因此我非常感谢您给出的枚举示例。我接受你的回答,但最后一个问题是:在文档中,它说的是
UIAlertAction.Style
,而不是
UIAlertActionStyle
(还有一个额外的句号)。知道为什么吗?它是
UIAlertAction.Style
。这意味着枚举是在
UIAlertAction
类中声明的。在枚举在类之外之前,所以枚举是
UIAlertActionStyle
例如:`class-UIAlertAction{enum-Style{case-default,destromical}}`您的代码片段说
UIAlertActionStyle
,但我猜那是打字错误?再次感谢您的帮助!我明白了,谢谢你的解释!我知道这是一个基本问题,但Swift如何推断
.default
意味着
UIAlertActionStyle.default
?是因为
UIAlertAction
style
必须是
UIAlertActionStyle
?因为函数的参数是UIAlertActionStyle类型,所以swift知道您不能再放一个类型。我明白了,谢谢。文档告诉我,
UIAlertAction.Style
是一个枚举-因此我非常感谢您给出的枚举示例。我接受你的回答,但最后一个问题是:在文档中,它说的是
UIAlertAction.Style
,而不是
UIAlertActionStyle
(还有一个额外的句号)。知道为什么吗?它是
UIAlertAction.Style
。这意味着枚举是在
UIAlertAction
类中声明的。在枚举在类之外之前,所以枚举是
UIAlertActionStyle
例如:`class-UIAlertAction{enum-Style{case-default,destromical}}`您的代码片段说
UIAlertActionStyle
,但我猜那是打字错误?再次感谢您的帮助!