Hello. I fixed JSON type to support @dynamicMemberLookup.
@dynamicMemberLookup
public enum JSON : Equatable, CustomStringConvertible {
...
public subscript(dynamicMember key: String) -> JSON {
guard case .object(let dict) = self[key], let value = dict[key] else {
return .invalid
}
return value
}
...
}
↓usage
// before
cell.textLabel?.text = tweets[indexPath.row]["text"].string
// after
cell.textLabel?.text = tweets[indexPath.row].text.string
Currently, when accessing the JSON content, we need to specify the key name with [""].
With support for @dynamicMemberLookup, we can access the JSON content without [""].
And the benefits of traditional JSON will not be lost.
Swift's strict typing system and doesn't require you to constantly downcast accessed objects. It also removes the need for lots of optional chaining
Could you confirm?
(I’m Sorry if this suggestion has already been considered.
I've checked the Issue and PR. But it may not be perfect...)
Hello. I fixed
JSON
type to support@dynamicMemberLookup
.↓usage
Currently, when accessing the JSON content, we need to specify the key name with
[""]
. With support for @dynamicMemberLookup, we can access the JSON content without[""]
. And the benefits of traditional JSON will not be lost.Could you confirm?
(I’m Sorry if this suggestion has already been considered. I've checked the Issue and PR. But it may not be perfect...)