Access control #228

Closed
opened 2025-12-29 15:27:00 +01:00 by adam · 2 comments
Owner

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 15:27:00 +01:00
adam closed this issue 2025-12-29 15:27:00 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Sep 10, 2018):

Make the property private and expose it through a computed property:

final class User: CoreStoreObject {
  var name: String? {
       return _name.value
  }
  private let _name = Value.Optional<String>("name")
}
@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") } ```
Author
Owner

@VincentSit commented on GitHub (Sep 21, 2018):

Thank you.

@VincentSit commented on GitHub (Sep 21, 2018): Thank you.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#228