-
Notifications
You must be signed in to change notification settings - Fork 29
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 querying helpers #3
Conversation
return nil | ||
} | ||
|
||
/// Return `true` iff this is `.null` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo "iff"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GenericJSON/Querying.swift
Outdated
/// | ||
/// If this is not an `.array` or the index is out of bounds, returns `nil`. | ||
public subscript(index: Int) -> JSON? { | ||
if case .array(let arr) = self, index < arr.count { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We check the upper bound of the array here, does it make sense to check the lower bound (i.e. index >= 0) too? Currently, an overflow in one direction returns nil
and the other direction will trigger a fatal index out of range exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Will do.
These are helpers to query values stored in a
JSON
value proposed by @cjmconie in #2. Cameron, is this OK? I have mostly just copied your code and added some tests.