Skip to content

[Swift] joined #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
seungchan2 opened this issue Jun 7, 2022 · 0 comments
Closed

[Swift] joined #74

seungchan2 opened this issue Jun 7, 2022 · 0 comments
Assignees
Labels

Comments

@seungchan2
Copy link
Owner

seungchan2 commented Jun 7, 2022

스크린샷 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를 넣어줄 수 있음 . .

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

@seungchan2 seungchan2 self-assigned this Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant