Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Swift] joined #74

@seungchan2

Description

@seungchan2

스크린샷 2022-06-07 오후 11 46 44

스크린샷 2022-06-07 오후 11 48 18

체크된 요일을

스크린샷 2022-06-07 오후 11 48 33

위와 같이 보여줘야함

ViewModel

 func selectDay(index: Int, isSelected: Bool) {
        let isBool = isSelected == false
        switch index {
        case 0:
            monday = isBool ? week[0] : ""
        case 1:
            tuesday = isBool ? week[1] : ""
        case 2:
            wednesday = isBool ? week[2] : ""
        case 3:
            thursday = isBool ? week[3] : ""
        case 4:
            friday = isBool ? week[4] : ""
        case 5:
            saturday = isBool ? week[5] : ""
        default:
            sunday = isBool ? week[6] : ""
        }
        days = monday + tuesday + wednesday + thursday + friday + saturday + sunday

TableViewCell

func checkImageIsHidden(_ dayViewModel: PillDayViewModel, indexPath: IndexPath) {
        checkImage.isHidden.toggle()
        isSelected.toggle()
        dayViewModel.selectDay(index: indexPath.row, isSelected: checkImage.isHidden)
    }

ViewController

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        guard let cell = tableView.cellForRow(at: indexPath) as? PillDayTableViewCell else { return }
        cell.checkImageIsHidden(viewModel, indexPath: indexPath)
    }

String ++ Extension

extension String {
    func addSeparator() -> String {
        let string = self.map{String($0)}
        let separator = string.joined(separator: ", ")
        return separator
    }
}

joined

배열에 특정 요소를 추가하여 묶는 방법

스크린샷 2022-06-07 오후 11 54 19

시퀀스 사이에 원하는 separator를 넣어줄 수 있음 . .

생각보다 너무 간단하고 유용한 듯 . .

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions