[swift-evolution] [Review] SE-0030 Property Behaviors

Joe Groff jgroff at apple.com
Wed Feb 17 13:18:29 CST 2016

If anyone wants to start playing with the feature, I now have some of the core functionality working in a branch:


I didn't want to waste time parsing a behavior declaration syntax while we're still painting the bikeshed, so behaviors are currently exposed as protocols with extension methods following a convention:

protocol delayedImmutable {
  // Type of the property.
  associatedtype Value
  // Storage required by the property.
  var storage: Value? { get set }
extension delayedImmutable {
  // Implementation of the property.
  var value: Value {
    // The property can only be read after it's been initialized.
    get {
      guard let theValue = storage else {
        fatalError("delayedImmutable property read before initialization")
      return theValue
    // The property can only be written once to initialize it.
    set {
      guard storage == nil else {
        fatalError("delayedImmutable property rewritten after initialization")
      storage = newValue

  // Initialization logic for the property storage.
  static func initStorage() -> Value? {
    return nil

Custom accessors and initializer expression bindings aren't handled yet, but there's enough there now to implement `delayed` initialization. Here's an example test case:


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160217/5eecaf35/attachment.html>

More information about the swift-evolution mailing list