Created
September 13, 2025 10:11
-
-
Save omidgolparvar/018a76344c73375755463c16c384b79b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// https://www.swiftbysundell.com/articles/let-vs-var-for-swift-struct-properties/ | |
| @propertyWrapper struct Readonly<Value> { | |
| let wrappedValue: Value | |
| } | |
| extension Readonly: Encodable where Value: Encodable { | |
| func encode(to encoder: Encoder) throws { | |
| var container = encoder.singleValueContainer() | |
| try container.encode(wrappedValue) | |
| } | |
| } | |
| extension Readonly: Decodable where Value: Decodable { | |
| init(from decoder: Decoder) throws { | |
| let container = try decoder.singleValueContainer() | |
| wrappedValue = try container.decode(Value.self) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment