What is the Swift syntax “ .bar” called?

ⅰ亾dé卋堺 提交于 2019-11-28 14:02:05

It is called an implicit member expression. From 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

From Apple's Swift book:

The values defined in an enumeration (such as north, south, east, and west) are its enumeration cases.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!