Skip to content

feat: RawRepresentable<Int/String> compatible with JSONSubscriptType - #1186

Open
nuomi1 wants to merge 2 commits into
SwiftyJSON:masterfrom
nuomi1:feature/JSONSubscriptType-RawRepresentable
Open

nuomi1 wants to merge 2 commits into
SwiftyJSON:masterfrom
nuomi1:feature/JSONSubscriptType-RawRepresentable

Conversation

@nuomi1

@nuomi1 nuomi1 commented Oct 9, 2025

Copy link
Copy Markdown

The PR should summarize what was changed and why. Here are some questions to
help you if you're not sure:

  • What behavior was changed?
  • What code was refactored / updated to support this change?
  • What issues are related to this PR? Or why was this change introduced?

Checklist - While not every PR needs it, new features should consider this list:

  • Does this have tests?
  • Does this have documentation?
  • Does this break the public API (Requires major version bump)?
  • Is this a new feature (Requires minor version bump)?


extension JSONSubscriptType where Self: RawRepresentable<Int> {
public var jsonKey: JSONKey {
return JSONKey.index(rawValue)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We can add handle negative rawValue, else it might crash at run time.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't think we need to handle negative rawValue, which is the same as Swift.Array, and it should crash when using negative rawValue as indices.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In other words, the caller should know that negative rawValue cannot be used here.

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.

3 participants