Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from Makeeyaf/bugfix/#3-binding-loop-fix
Browse files Browse the repository at this point in the history
#3 첫 이벤트는 무시해서 바인딩이 루프에 빠지지 않도록 함
  • Loading branch information
Makeeyaf committed Jan 16, 2021
2 parents 5b0b95f + 93f14fd commit 3228d07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion BindingWithCell/Cell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ final class RxCell: UITableViewCell {
final class CombineCell: UITableViewCell {
static let reuseID = String(describing: self)

@Published var isOn: Bool = false
@Published var isOn: Bool = true

// MARK: Views

Expand Down
5 changes: 2 additions & 3 deletions BindingWithCell/CombineViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ extension CombineViewController: UITableViewDelegate, UITableViewDataSource {
cell.titleLabel.text = data[indexPath.row].title
cell.toggleSwitch.isOn = data[indexPath.row].isOn

cell.$isOn.removeDuplicates()
cell.$isOn.dropFirst()
.removeDuplicates()
.subscribe(on: DispatchQueue.main)
.sink { [weak self] isOn in
print("Sink, \(isOn)")
self?.data[indexPath.row].isOn = isOn
self?.tableView.reloadData()
}
.store(in: &bag)
print("bag: \(bag.count)")
return cell
}
}

0 comments on commit 3228d07

Please sign in to comment.