Skip to content
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

Add the state property to Sheet. #177

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

maciejtrybilo
Copy link

This adds the possibility to check the state of the worksheet. In particular it allows seeing whether the sheet is hidden or visible.

@@ -45,11 +45,13 @@ public struct Workbook: Codable, Equatable {
public let name: String?
public let id: String
public let relationship: String
public let state: String?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In contrast to name, id and relationship - state seems to me more fit to be an enum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please (re-)mark me for review so that I see it in my list of open PRs to review when you're ready

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I didn't use an enum because I've no idea what are the possible values. I've seen "visible", "hidden", and "veryHidden" XD
I guess people can add if they know about other states.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't know the exhaustive list of states, let's do a struct similar to this instead:

public struct State: RawRepresentable, Codable {
  public var rawValue: String
  
  public func encode(to encoder: Encoder) throws {
    var container = encoder.singleValueContainer()
    try container.encode(rawValue)
  }
  
  public init(from decoder: Decoder) throws {
    let container = try decoder.singleValueContainer()
    self.rawValue = try container.decode(String.self)
  }
  
  public static let visible = State(rawValue: "visible")
  public static let hidden = State(rawValue: "hidden")
  public static let veryHidden = State(rawValue: "veryHidden")
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please tag me again when you have a reply/updated the code. Sorry about the ping-ponging, but if we don't know the exhaustive list of cases, we cannot use an enum at this stage. Swift doesn't allow libraries to have unknown future cases using @unknown default:

@Joannis Joannis removed their request for review December 4, 2023 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants