4 ms·
filter -> flatMap / compactMap without arguments orElseThrow is something you might need more often in Java, Swift handles optionals with if let / else checks
by dep_b 8y ago
filter -> flatMap / compactMap without arguments
orElseThrow is something you might need more often in Java, Swift handles optionals with if let / else checks or Result enums instead of functions that either result an object or throw an Exception. Throwing errors / exceptions is pretty rare in the language compared to the Java / C# world.
Only when doing stuff like mapping JSON I set up try / throw trees because in the end I might not care about the Error at all and just discard it.
- stiGGG 8y agoAnd with Codable times of manually mapping JSON to objects are over, at least you have to deal with something sane.
- dep_b 8y agoI really needed stuff like snake_case support
- saagarjha 8y agoCodableKeys should let you handle this.
- bunnycorn 8y agohttps://developer.apple.com/documentation/foundation/jsonencoder/keyencodingstrategy/converttosnakecase https://developer.apple.com/documentation/foundation/jsonenc... Also, as already said, CodingKeys.
- dep_b 8y agoRight, I said needed, not need ;)