Last active
September 21, 2017 14:28
-
-
Save cocoahero/232f710f14a7546cffe4dc9773b88c9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [Foundation.(_JSONKey in _12768CA107A31EF2DCE034FD75B541C9)(stringValue: "Index 3", intValue: Optional(3))], debugDescription: "Cannot initialize Season from invalid String value fall", underlyingError: nil)): file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-900.0.65/src/swift/stdlib/public/core/ErrorType.swift, line 181 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum Season: String, Codable { | |
case winter | |
case spring | |
case summer | |
case autumn | |
} | |
let json = """ | |
["winter", "spring", "summer", "fall"] | |
""".data(using: .utf8)! | |
// Is there a way to "skip" failing items instead of erroring on the entire array? | |
let seasons = try! JSONDecoder().decode([Season].self, from: json) | |
print(seasons) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment