- Proposal: SE-0087
- Author: Anton3
- Status: Rejected (Rationale)
- Review manager: Chris Lattner
Make lazy declaration modifier an attribute by renaming it to @lazy. Example:
struct ResourceManager {
@lazy var resource: NSData = loadResource()
}Swift-evolution thread: link to the discussion thread for that proposal
Swift's rule for attribues/keywords is that keywords usually modify type of variable; attributes do not.
lazy clearly does not modify type of its variable, it only delays side effects of its initializer.
Type of resource in the example above is still NSData.
Many other similar declaration modifiers are already attributes:
@available,@objc,@nonobjc,@NSCopying,@NSManaged,@IBOutlet, etc
Remove lazy keyword, add @lazy attribute and add migration rule to replace them.
Many people look forward to "Property behaviours" proposal for Swift 4. It allows to create declaration modifiers using Swift language.
@lazy is one of the main candidates for being extracted into standard library.
But to do so, we must first make it an attribute.
Because it is a breaking change, the earlier, the better.
This is a breaking change, but migration is trivial.