Using leading dot syntax in generic functions
Leading dot syntax in Swift
The “leading dot syntax” is an important feature in Swift to provide clean and concise APIs for callers. It supports enums and static members.
Let’s say we have an ItemStorage class that can store Item. We can define Item as enum:
class ItemStorage { |
At the call site, we can just use .one in the store(_:) function:
let storage = ItemStorage() |
Alternatively, we can change Item to struct and declare commonly used values as the static variables to make them available in leading dot syntax:
struct Item { |