am试图用JSON服务器响应中的部分填充tableview中的日期...
这些部分将是日期..我想将具有相同日期的对象添加到同一部分...
我正试图这样做:
print("heree:")
print(matches.data?.count)
for matchdate in matches.data!{
datesarray.append(matchdate.dateGregorian!)
}
datesarray = datesarray.reduce([], {
$0.contains($1) ? $0 : $0 + [$1]
})
print(datesarray.count)
for date in datesarray{
for match in matches.data!{
if date == match.dateGregorian{
homeimg = clubImg(id: match.home!)
awayimg = clubImg(id: match.away!)
matchesarray.append(Matches2(homeimg: homeimg,homenamear: match.homeClubNameAr,awayimg: awayimg,awaynamear: match.awayClubNameAr,matchtime: match.dateHijri))
}
self.objectArray.append(Sections(sectionDate: date, sectionMatches: matchesarray))
}
}
DispatchQueue.main.async {
self.tableview.reloadData()
}
print("heree2:")
print(self.objectArray.count)
但是得到一个非常错误的结果!
json返回一个包含149个对象的数组.. uniq数组包含74个..最后tableview数组包含11026个对象!!!!如何以及为什么?
做错了什么以及如何解决呢?
答案 0 :(得分:0)
您可以尝试
for date in datesarray{
matchesarray.removeAll()
for match in matches.data!{
if date == match.dateGregorian{
homeimg = clubImg(id: match.home!)
awayimg = clubImg(id: match.away!)
matchesarray.append(Matches2(homeimg: homeimg,homenamear: match.homeClubNameAr,awayimg: awayimg,awaynamear: match.awayClubNameAr,matchtime: match.dateHijri))
}
}
self.objectArray.append(Sections(sectionDate: date, sectionMatches: matchesarray))
}