@@ -39,19 +39,22 @@ public struct StatsSummaryData {
3939 public let visitorsCount : Int
4040 public let likesCount : Int
4141 public let commentsCount : Int
42+ public let postsCount : Int ?
4243
4344 public init ( period: StatsPeriodUnit ,
4445 periodStartDate: Date ,
4546 viewsCount: Int ,
4647 visitorsCount: Int ,
4748 likesCount: Int ,
48- commentsCount: Int ) {
49+ commentsCount: Int ,
50+ postsCount: Int ? ) {
4951 self . period = period
5052 self . periodStartDate = periodStartDate
5153 self . viewsCount = viewsCount
5254 self . visitorsCount = visitorsCount
5355 self . likesCount = likesCount
5456 self . commentsCount = commentsCount
57+ self . postsCount = postsCount
5558 }
5659}
5760
@@ -101,13 +104,18 @@ extension StatsSummaryTimeIntervalData: StatsTimeIntervalData {
101104 self . period = period
102105 self . unit = unit
103106 self . periodEndDate = date
104- self . summaryData = data. compactMap { StatsSummaryData ( dataArray: $0,
105- period: unit ?? period,
106- periodIndex: periodIndex,
107- viewsIndex: viewsIndex,
108- visitorsIndex: visitorsIndex,
109- likesIndex: likesIndex,
110- commentsIndex: commentsIndex) }
107+ self . summaryData = data. compactMap {
108+ StatsSummaryData (
109+ dataArray: $0,
110+ period: unit ?? period,
111+ periodIndex: periodIndex,
112+ viewsIndex: viewsIndex,
113+ visitorsIndex: visitorsIndex,
114+ likesIndex: likesIndex,
115+ commentsIndex: commentsIndex,
116+ postsIndex: fieldsArray. firstIndex ( of: " posts " )
117+ )
118+ }
111119 }
112120}
113121
@@ -118,7 +126,8 @@ private extension StatsSummaryData {
118126 viewsIndex: Int ? ,
119127 visitorsIndex: Int ? ,
120128 likesIndex: Int ? ,
121- commentsIndex: Int ? ) {
129+ commentsIndex: Int ? ,
130+ postsIndex: Int ? ) {
122131
123132 guard
124133 let periodString = dataArray [ periodIndex] as? String ,
@@ -130,6 +139,7 @@ private extension StatsSummaryData {
130139 let visitorsCount : Int
131140 let likesCount : Int
132141 let commentsCount : Int
142+ var postsCount : Int ?
133143
134144 if let viewsIndex = viewsIndex {
135145 guard let count = dataArray [ viewsIndex] as? Int else {
@@ -167,13 +177,18 @@ private extension StatsSummaryData {
167177 commentsCount = 0
168178 }
169179
180+ if let postsIndex {
181+ postsCount = dataArray [ postsIndex] as? Int
182+ }
183+
170184 self . period = period
171185 self . periodStartDate = periodStart
172186
173187 self . viewsCount = viewsCount
174188 self . visitorsCount = visitorsCount
175189 self . likesCount = likesCount
176190 self . commentsCount = commentsCount
191+ self . postsCount = postsCount
177192 }
178193
179194 static func parsedDate( from dateString: String , for period: StatsPeriodUnit ) -> Date ? {
@@ -271,12 +286,16 @@ extension StatsLikesSummaryTimeIntervalData: StatsTimeIntervalData {
271286
272287 self . period = period
273288 self . periodEndDate = date
274- self . summaryData = data. compactMap { StatsSummaryData ( dataArray: $0,
275- period: unit ?? period,
276- periodIndex: periodIndex,
277- viewsIndex: nil ,
278- visitorsIndex: nil ,
279- likesIndex: likesIndex,
280- commentsIndex: nil ) }
289+ self . summaryData = data. compactMap {
290+ StatsSummaryData (
291+ dataArray: $0,
292+ period: unit ?? period,
293+ periodIndex: periodIndex,
294+ viewsIndex: nil ,
295+ visitorsIndex: nil ,
296+ likesIndex: likesIndex,
297+ commentsIndex: nil , postsIndex: nil
298+ )
299+ }
281300 }
282301}
0 commit comments