QuaRang1225 / project-WhereAreWeGoing

1 stars 0 forks source link

캘린더 뷰 에러 #23

Closed QuaRang1225 closed 1 year ago

QuaRang1225 commented 1 year ago

캘린더에서 가장 빠른 일정의 페이지만 정보가 보임

QuaRang1225 commented 1 year ago

원인

기존코드

let dateRange = vm.pages.map({$0.dateRange.map({$0.dateValue().toStringCalender()})})
    for dates in dateRange{
        if dates.contains(dateFormatter.string(from: date)){
            print(vm.page)
            vm.page = vm.pages.first(where:{$0.dateRange.map({$0.dateValue().toStringCalender()}).contains(Timestamp(date: date).dateValue().toStringCalender())})
        }else{
            print(vm.page)
            vm.page = nil
        }
}

바뀐 코드

let dateRange = vm.pages.map({$0.dateRange.map({$0.dateValue().toStringCalender()})})

let dateArr = dateRange.first(where: {$0.contains(dateFormatter.string(from: date))})
guard dateArr != nil else{ return vm.page = nil }
vm.page = vm.pages.first(where:{$0.dateRange.map({$0.dateValue().toStringCalender()}).contains(Timestamp(date: date).dateValue().toStringCalender())})