Originally created by @VincentSit on GitHub (Aug 12, 2018).
I am trying to use CoreStore in my project, I found that all fields in the Demo are declared with let , and there seems to be no way to set access controls, i.e. read-only variables.
A very common usage scenario is:
final class User: CoreStoreObject {
// Cannot be modified after initialization.
let identifier = Value.Requited<String>("identifier", initial: "")
// Can only be modified internally.
private(set) var name = Value.Optional<String>("name")
func update(name: String?, completion: Completion?) {
// Perform a network request...
self.name = name
}
}
In the above example, I want to only allow name to be modified inside the class, the external can only be read.
What should I do?
Originally created by @VincentSit on GitHub (Aug 12, 2018).
I am trying to use CoreStore in my project, I found that all fields in the Demo are declared with `let` , and there seems to be no way to set access controls, i.e. read-only variables.
A very common usage scenario is:
```
final class User: CoreStoreObject {
// Cannot be modified after initialization.
let identifier = Value.Requited<String>("identifier", initial: "")
// Can only be modified internally.
private(set) var name = Value.Optional<String>("name")
func update(name: String?, completion: Completion?) {
// Perform a network request...
self.name = name
}
}
```
In the above example, I want to only allow `name` to be modified inside the class, the external can only be read.
What should I do?
adam
added the question label 2025-12-29 18:24:35 +01:00
@JohnEstropia commented on GitHub (Sep 10, 2018):
Make the property `private` and expose it through a computed property:
```swift
final class User: CoreStoreObject {
var name: String? {
return _name.value
}
private let _name = Value.Optional<String>("name")
}
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @VincentSit on GitHub (Aug 12, 2018).
I am trying to use CoreStore in my project, I found that all fields in the Demo are declared with
let, and there seems to be no way to set access controls, i.e. read-only variables.A very common usage scenario is:
In the above example, I want to only allow
nameto be modified inside the class, the external can only be read.What should I do?
@JohnEstropia commented on GitHub (Sep 10, 2018):
Make the property
privateand expose it through a computed property:@VincentSit commented on GitHub (Sep 21, 2018):
Thank you.