-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REQ][SWIFT5] Readonly properties on struct models #6046
Labels
Comments
iliaskarim
changed the title
[REQ][SWIFT4][SWIFT5] Immutable value types
[REQ][SWIFT5] Immutable value types
Apr 24, 2020
iliaskarim
changed the title
[REQ][SWIFT5] Immutable value types
[REQ][SWIFT5] Immutable properties on struct models
Apr 24, 2020
iliaskarim
changed the title
[REQ][SWIFT5] Immutable properties on struct models
[REQ][SWIFT5] Readonly properties on struct models
Apr 24, 2020
This was referenced Dec 27, 2023
This was referenced Dec 28, 2023
This was referenced Dec 29, 2023
This was referenced Jan 5, 2024
This was referenced Jan 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Structs support immutability after initialization. Immutable data types, particularly value types like structs, encourage functional programming practices. By reducing shared mutable state inherit in objects with mutable properties, using immutable value types makes it less likely that UI appears out of sync with an application's data.
Describe the solution you'd like
Swift4/5 structs, when built without Objective-C compatibility, rather than declaring their properties with the
var
keyword, can useprivate(set) var
keywords to make them only be mutated by the struct's initializer.This solution could be enabled through an additional property that defaults to false.
Describe alternatives you've considered
The
let
keyword for properties on structs cannot be combined with default values. So, to keep the syntax consistent between properties that have default values and those that don't, useprivate(set) var
instead.Additional context
The text was updated successfully, but these errors were encountered: