Skip to content

Commit

Permalink
Merge pull request #2682 from square/use_setters_for_defaults
Browse files Browse the repository at this point in the history
[swift] Add setter for ProtoDefaulted and CustomDefaulted
  • Loading branch information
dnkoutso authored Oct 16, 2023
2 parents fa69a5d + e306fa3 commit 86caab7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ _Unreleased_
* Similar to `CustomDefaulted, this adds as projection of the protocol defined default value
* This should not take up any additional storage
* This is attached to optional scalar values and messages with entirely optional values
* New: `ProtoDefaulted` and `CustomDefaulted` include setter support
* This enables you to do something like `Foo().$bar.$baz += 1`

Version 4.9.1
-------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public struct CustomDefaulted<Value> {
}

public var projectedValue: Value {
wrappedValue ?? defaultValue
get {
wrappedValue ?? defaultValue
}
set {
wrappedValue = newValue
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public struct ProtoDefaulted<Value: ProtoDefaultedValue> {
}

public var projectedValue: Value {
wrappedValue ?? Value.defaultedValue
get {
wrappedValue ?? Value.defaultedValue
}
set {
wrappedValue = newValue
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ class SwiftGenerator private constructor(
.build()

fileMembers += FileMemberSpec.builder(memberwiseExtension)
.addGuard("$FLAG_INCLUDE_MEMBERWISE_INITIALIZER")
.addGuard(FLAG_INCLUDE_MEMBERWISE_INITIALIZER)
.build()
}

Expand Down Expand Up @@ -1256,7 +1256,7 @@ class SwiftGenerator private constructor(
.build()

fileMembers += FileMemberSpec.builder(memberwiseExtension)
.addGuard("$FLAG_INCLUDE_MEMBERWISE_INITIALIZER")
.addGuard(FLAG_INCLUDE_MEMBERWISE_INITIALIZER)
.build()
}

Expand Down

0 comments on commit 86caab7

Please sign in to comment.