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

Commit 269029d

Browse files
committed
Insights All Time: only fail parsing if critical data is missing.
1 parent 05f213a commit 269029d

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

WordPressKit/Insights/StatsAllTimesInsight.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@ extension StatsAllTimesInsight: StatsInsightData {
2525
public init?(jsonDictionary: [String: AnyObject]) {
2626
guard
2727
let statsDict = jsonDictionary["stats"] as? [String: AnyObject],
28-
let postsCount = statsDict["posts"] as? Int,
29-
let viewsCount = statsDict["views"] as? Int,
30-
let visitorsCount = statsDict["visitors"] as? Int,
31-
let bestViewsPerDayCount = statsDict["views_best_day_total"] as? Int,
3228
let bestViewsDayString = statsDict["views_best_day"] as? String,
3329
let bestViewsDay = StatsAllTimesInsight.dateFormatter.date(from: bestViewsDayString)
3430
else {
3531
return nil
3632
}
3733

38-
self.postsCount = postsCount
39-
self.bestViewsPerDayCount = bestViewsPerDayCount
40-
self.visitorsCount = visitorsCount
41-
self.viewsCount = viewsCount
34+
self.postsCount = statsDict["posts"] as? Int ?? 0
35+
self.bestViewsPerDayCount = statsDict["views_best_day_total"] as? Int ?? 0
36+
self.visitorsCount = statsDict["visitors"] as? Int ?? 0
37+
self.viewsCount = statsDict["views"] as? Int ?? 0
4238
self.bestViewsDay = bestViewsDay
4339
}
4440

0 commit comments

Comments
 (0)