Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 2ac4c46

Browse files
committed
Update StatsAnnualAndMostPopularTimeInsight decoding to be more permitting
1 parent c6c6eeb commit 2ac4c46

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

WordPressKit/Insights/StatsAnnualAndMostPopularTimeInsight.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ public struct StatsAnnualAndMostPopularTimeInsight: Codable {
4040
case totalImages = "total_images"
4141
case averageImages = "avg_images"
4242
}
43+
44+
public init(from decoder: Decoder) throws {
45+
let container = try decoder.container(keyedBy: CodingKeys.self)
46+
year = try container.decode(String.self, forKey: .year)
47+
totalPosts = (try? container.decodeIfPresent(Int.self, forKey: .totalPosts)) ?? 0
48+
totalWords = (try? container.decode(Int.self, forKey: .totalWords)) ?? 0
49+
averageWords = (try? container.decode(Double.self, forKey: .averageWords)) ?? 0
50+
totalLikes = (try? container.decode(Int.self, forKey: .totalLikes)) ?? 0
51+
averageLikes = (try? container.decode(Double.self, forKey: .averageLikes)) ?? 0
52+
totalComments = (try? container.decode(Int.self, forKey: .totalComments)) ?? 0
53+
averageComments = (try? container.decode(Double.self, forKey: .averageComments)) ?? 0
54+
totalImages = (try? container.decode(Int.self, forKey: .totalImages)) ?? 0
55+
averageImages = (try? container.decode(Double.self, forKey: .averageImages)) ?? 0
56+
}
4357
}
4458
}
4559

0 commit comments

Comments
 (0)