iOS Swift/Today I Learned

filter 및 tableView section 활용하기

호두빵 2022. 12. 30. 15:13

var contentCount = authHistories.filter({$0.regDtString.split(separator: ",").first! > authSection[indexPath.section]}).count
cell.authTimeLabel.text = authHistories[indexPath.row + contentCount].regDtString

만약 여러가지 목록 중에서 해당 일자를 기준으로 그 이후에 일어난 사건에 대해 섹션으로 분리를 해야한다면, filter를 사용해서 일자값만 추출한 다음에 기준으로 잡을 해당 일자보다 더 앞선 컨텐츠만 count로 잡을 수 있습니다. 그런 다음 셀의 위치를 알려줄 때에는 indexPath.row에 contentCount를 더해서 전달해주면 됩니다.