3
votes

I've been reading Apple's Swift Programming Language book (the version updated for Swift 2.0) and I've found something rather curious. In Language Reference > Lexical Stricture > Keywords and Punctuation (link here - but you need to scroll down a bit) there's a list of language keywords. A few of them haven't been explained anywhere.

Keywords reserved in particular contexts: associativity, convenience, dynamic, didSet, final, get, infix, inout, lazy, left, mutating, none, nonmutating, optional, override, postfix, precedence, prefix, Protocol, required, right, set, Type, unowned, weak, and willSet. Outside the context in which they appear in the grammar, they can be used as identifiers.

Do you have any clue what they do/mean or where to find applicable information?

2

2 Answers

4
votes

left, right and none are used to specify the associativity of a custom operator:

The associativity of an operator specifies how a sequence of operators with the same precedence level are grouped together in the absence of grouping parentheses. You specify the associativity of an operator by writing the context-sensitive keyword associativity followed by the associativity, which is one of the context-sensitive keywords left, right, or none.

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/associativity

Type is used with meta-types:

A metatype type refers to the type of any type, including class types, structure types, enumeration types, and protocol types.

The metatype of a class, structure, or enumeration type is the name of that type followed by .Type.

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/swift/grammar/metatype-type

4
votes

left, right and none are used for associativity ordering when declaring operators, such as:

infix operator ⊕ { associativity left precedence 140 }

See the Apple docs