Skip to content

Commit

Permalink
Fix: Parse enums with fallback to the unknown value
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-chekyrta committed Jan 3, 2024
1 parent cec9f29 commit 790e4e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Core/Core/Data/Model/Data_Dashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ public extension DataLayer {
case organization = "Organization"
case univerity = "Univerity"
case university = "University"
case unknown

public init(from decoder: Decoder) throws {
let rawValue = try decoder.singleValueContainer().decode(RawValue.self)
self = Org(rawValue: rawValue) ?? .unknown
}
}

// MARK: - CourseMode
Expand Down Expand Up @@ -222,6 +228,12 @@ public extension DataLayer {
case audit
case honor
case verified
case unknown

public init(from decoder: Decoder) throws {
let rawValue = try decoder.singleValueContainer().decode(RawValue.self)
self = Mode(rawValue: rawValue) ?? .unknown
}
}

// MARK: - CourseSharingUtmParameters
Expand Down
8 changes: 7 additions & 1 deletion Core/Core/Data/Model/Data_Discovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ public extension DataLayer {
}

enum StartType: String, Codable {
case empty
case timestamp
case empty
case unknown

public init(from decoder: Decoder) throws {
let rawValue = try decoder.singleValueContainer().decode(RawValue.self)
self = StartType(rawValue: rawValue) ?? .unknown
}
}
}

Expand Down

0 comments on commit 790e4e2

Please sign in to comment.