carson-katri / carson-katri/swift-request
Issue with subscript not existing causing crash
- Dominant language
- Swift
- Stars
- 740
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
Description
Ive stumbled upon a case where my server returned a partially formed body that doesnt include a key.
I see no way in the api to safely access a subscript that may not exist.
Json line 65: `json.jsonData = (jsonData as! [String: Any])[s]!`
My code:
```swift
.onJson { j in
print(j)
if j.stringified?.contains("script") != nil { // added to get around the crash
$script.wrappedValue = j["script"].string
} // added
}
```
Id expect nil as opposed to a crash. I think thats what js would do, just return undefined for a non existing key instead of treating it as an error.
In my xp, though I use force unwraps , I nearly always end up reverting them.
Contributor guide
Assessment
This issue has not been assessed yet.