Swift 语法“.bar”叫什么?
What is the Swift syntax " .bar" called?
Swift 有这个方便的语法:
enum Foo {
case bar
case baz
}
func hoge(foo: Foo) {
}
hoge(foo: .bar) // This
镜像在 enum
s 以外的地方:
struct Qux {
static let `default` = Qux()
}
func hoge(qux: Qux) {
}
hoge(qux: .default) // This
我不确定在对话/工单中如何称呼它。也许 "type-inferred dot syntax"?我不确定。 这个语法有正式名称吗?如果有,它是什么?
来自苹果的Swift book:
The values defined in an enumeration (such as north, south, east, and west) are its enumeration cases.
它被称为隐式成员表达式。来自 the grammar section of the language guide:
An implicit member expression is an abbreviated way to access a member
of a type, such as an enumeration case or a type method, in a context
where type inference can determine the implied type. It has the
following form:
.member name
For example:
var x = MyEnumeration.someValue
x = .anotherValue
Swift 有这个方便的语法:
enum Foo {
case bar
case baz
}
func hoge(foo: Foo) {
}
hoge(foo: .bar) // This
镜像在 enum
s 以外的地方:
struct Qux {
static let `default` = Qux()
}
func hoge(qux: Qux) {
}
hoge(qux: .default) // This
我不确定在对话/工单中如何称呼它。也许 "type-inferred dot syntax"?我不确定。 这个语法有正式名称吗?如果有,它是什么?
来自苹果的Swift book:
The values defined in an enumeration (such as north, south, east, and west) are its enumeration cases.
它被称为隐式成员表达式。来自 the grammar section of the language guide:
An implicit member expression is an abbreviated way to access a member of a type, such as an enumeration case or a type method, in a context where type inference can determine the implied type. It has the following form:
.
member name
For example:
var x = MyEnumeration.someValue x = .anotherValue