Skip to content
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

[버그] withUnretained 걷어내기 #73

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,24 @@ class ItemDetailViewController: UIViewController {

reactor.state.map { $0.isAcquired }
.observe(on: MainScheduler.instance)
.withUnretained(self)
.subscribe(onNext: { owner, isAcquired in
.subscribe(onNext: { [weak self] isAcquired in
let config = UIImage.SymbolConfiguration(scale: .large)
owner.checkButton.setImage(
self?.checkButton.setImage(
UIImage(systemName: isAcquired ? "checkmark.seal.fill" : "checkmark.seal", withConfiguration: config),
for: .normal
)
}).disposed(by: disposeBag)

itemVariantsColorView?.didTapImage
.compactMap { $0 }
.withUnretained(self)
.subscribe(onNext: { owner, image in
owner.itemDetailInfoView?.changeImage(image)
.subscribe(onNext: { [weak self] image in
self?.itemDetailInfoView?.changeImage(image)
}).disposed(by: disposeBag)

itemVariantsPatternView?.didTapImage
.compactMap { $0 }
.withUnretained(self)
.subscribe(onNext: { owner, image in
owner.itemDetailInfoView?.changeImage(image)
.subscribe(onNext: { [weak self] image in
self?.itemDetailInfoView?.changeImage(image)
}).disposed(by: disposeBag)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,16 @@ class ItemsViewController: UIViewController {
selectedKeyword
.filter { $0.isEmpty == false }
.map { !$0.keys.contains(.all) }
.withUnretained(self)
.observe(on: MainScheduler.instance)
.subscribe(onNext: { owner, isFiltering in
.subscribe(with: self, onNext: { owner, isFiltering in
owner.navigationItem.rightBarButtonItem?.image = UIImage(
systemName: isFiltering ? "arrow.up.arrow.down.circle.fill" : "ellipsis.circle"
)
}).disposed(by: disposeBag)

searchController.searchBar.rx.text
.map { $0 != "" }
.withUnretained(self)
.subscribe(onNext: { owner, isSearching in
.subscribe(with: self, onNext: { owner, isSearching in
if isSearching {
owner.emptyView.editLabel(
title: "Item is empty.".localized,
Expand All @@ -214,8 +212,7 @@ class ItemsViewController: UIViewController {
searchController.searchBar.rx.selectedScopeButtonIndex
.compactMap { SearchScope.allCases[safe: $0] }
.observe(on: MainScheduler.asyncInstance)
.withUnretained(self)
.subscribe(onNext: { owner, currentScope in
.subscribe(with: self, onNext: { owner, currentScope in
switch currentScope {
case .all:
owner.emptyView.editLabel(
Expand Down Expand Up @@ -390,17 +387,19 @@ extension ItemsViewController {
title: Menu.allSelect.title,
image: UIImage(systemName: "text.badge.checkmark")
) { [weak self] action in
guard let self = self else {
guard let owner = self else {
return
}
self.showAlert(title: "Notice".localized, message: "Are you sure you want to check them all?".localized)
owner.showAlert(title: "Notice".localized, message: "Are you sure you want to check them all?".localized)
.filter { $0 == true }
.withUnretained(self)
.subscribe(onNext: { owner, _ in
.subscribe(onNext: { [weak owner] _ in
guard let owner else {
return
}
owner.reactor.action.onNext(.selectedMenu(keywords: [.allSelect: ""]))
owner.selectedKeyword.accept(owner.selectedKeyword.value)
}).disposed(by: self.disposeBag)
self.navigationItem.rightBarButtonItem?.menu = self.createMoreMenu()
}).disposed(by: owner.disposeBag)
owner.navigationItem.rightBarButtonItem?.menu = owner.createMoreMenu()
}
let resetAction = UIAction(
title: Menu.reset.title,
Expand All @@ -411,8 +410,7 @@ extension ItemsViewController {
}
self.showAlert(title: "Notice".localized, message: "Are you sure you want to uncheck them all?".localized)
.filter { $0 == true }
.withUnretained(self)
.subscribe(onNext: { owner, _ in
.subscribe(with: self, onNext: { owner, _ in
owner.reactor.action.onNext(.selectedMenu(keywords: [.reset: ""]))
owner.selectedKeyword.accept(owner.selectedKeyword.value)
}).disposed(by: self.disposeBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ final class CatalogCellReactor: Reactor {
case .fetch:
let collectedState = Items.shared.itemList
.take(1)
.withUnretained(self)
.compactMap { owner, items in
items[owner.currentState.category]?.contains(owner.item)
.compactMap { [weak self] items in
guard let owner = self else {
return nil
}
return items[owner.currentState.category]?.contains(owner.item)
}.map { Mutation.setAcquired($0) }
return collectedState

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ final class ItemDetailReactor: Reactor {
case .fetch:
let collectedState = Items.shared.itemList
.take(1)
.withUnretained(self)
.compactMap { owner, items in
items[owner.currentState.item.category]
}.withUnretained(self).map { owner, items -> Mutation in Mutation.setAcquired(items.contains(owner.currentState.item))
.compactMap { [weak self] items -> [Item]? in
guard let owner = self else {
return nil
}
return items[owner.currentState.item.category]
}
.compactMap { [weak self] items -> Mutation? in
guard let owner = self else {
return nil
}
return Mutation.setAcquired(items.contains(owner.currentState.item))
}
return collectedState

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ final class ItemsReactor: Reactor {
let newAllItems = setUpItems().map { Mutation.setAllItems($0) }
let collectedItems = setUpUserItem()
let notCollectedIems = setUpUserItem()
.withUnretained(self)
.map { owner, items in owner.setUpNotCollected(items) }
.compactMap { [weak self] items in self?.setUpNotCollected(items) }
let userItems = Observable.combineLatest(collectedItems, notCollectedIems)
.map { Mutation.setUserItems(collected: $0.0, notCollected: $0.1) }
let loadingState = Items.shared.isLoading.map { Mutation.setLoadingState($0) }
Expand All @@ -91,14 +90,21 @@ final class ItemsReactor: Reactor {
lastSearchKeyword = text.lowercased()
guard text != "" else {
return currentItems()
.withUnretained(self)
.map { owner, items in owner.filtered(items: items, keywords: owner.currentKeywords) }
.compactMap { [weak self] items in
guard let owner = self else {
return nil
}
return owner.filtered(items: items, keywords: owner.currentKeywords)
}
.map { .setItems($0) }
}
return currentItems()
.withUnretained(self)
.map { owner, items -> [Item] in
owner.filtered(
.compactMap { [weak self] items -> [Item]? in
guard let owner = self else {
return nil
}

return owner.filtered(
items: owner.search(items: items, text: text.lowercased()),
keywords: owner.currentKeywords
)
Expand All @@ -114,9 +120,9 @@ final class ItemsReactor: Reactor {
case .selectedMenu(let keywords):
currentKeywords = keywords
return currentItems()
.withUnretained(self)
.map { owner, items -> [Item] in
owner.filtered(
.map { [weak self] items -> [Item] in
guard let owner = self else { return [] }
return owner.filtered(
items: owner.search(items: items, text: owner.lastSearchKeyword),
keywords: keywords
)
Expand Down Expand Up @@ -258,16 +264,21 @@ final class ItemsReactor: Reactor {
switch mode {
case .all:
return Items.shared.categoryList
.withUnretained(self)
.compactMap { owner, items in
items[owner.currentState.category]
.compactMap { [weak self] items in
guard let owner = self else {
return nil
}

return items[owner.currentState.category]
}

case .user:
return Items.shared.itemList
.withUnretained(self)
.map { owenr, items in
items[owenr.currentState.category] ?? []
.map { [weak self] items in
guard let owner = self else {
return []
}
return items[owner.currentState.category] ?? []
}

case .keyword(let title, let category):
Expand All @@ -280,9 +291,11 @@ final class ItemsReactor: Reactor {
switch mode {
case .all:
return Items.shared.itemList
.withUnretained(self)
.map { owenr, items in
items[owenr.currentState.category] ?? []
.map { [weak self] items in
guard let owner = self else {
return []
}
return items[owner.currentState.category] ?? []
}

case .keyword(let title, _):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ class CatalogCell: UICollectionViewCell {
reactor.state.map { $0.isAcquired }
.compactMap { $0 }
.observe(on: MainScheduler.instance)
.withUnretained(self)
.subscribe(onNext: { owner, isAcquired in
.subscribe(onNext: { [weak self] isAcquired in
let config = UIImage.SymbolConfiguration(font: .preferredFont(forTextStyle: .title2))
owner.checkButton.setImage(
self?.checkButton.setImage(
UIImage(
systemName: isAcquired ? "checkmark.seal.fill" : "checkmark.seal",
withConfiguration: config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@ class ItemSeasonView: UIView {

Items.shared.userInfo
.compactMap { $0?.hemisphere }
.withUnretained(self)
.observe(on: MainScheduler.instance)
.subscribe(onNext: { owner, hemisphere in
.subscribe(onNext: { [weak self] hemisphere in
switch hemisphere {
case .south:
owner.setUpTime(times: item.hemispheres?.south.time ?? [])
owner.setUpCalendar(months: item.hemispheres?.south.monthsArray ?? [])
self?.setUpTime(times: item.hemispheres?.south.time ?? [])
self?.setUpCalendar(months: item.hemispheres?.south.monthsArray ?? [])
case .north:
owner.setUpTime(times: item.hemispheres?.north.time ?? [])
owner.setUpCalendar(months: item.hemispheres?.north.monthsArray ?? [])
self?.setUpTime(times: item.hemispheres?.north.time ?? [])
self?.setUpCalendar(months: item.hemispheres?.north.monthsArray ?? [])
}
}).disposed(by: disposeBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ class ItemVariantsView: UIView {
}.disposed(by: disposeBag)

collectionView.rx.itemSelected
.withUnretained(self)
.subscribe(onNext: { owner, indexPath in
let cell = owner.collectionView.cellForItem(at: indexPath) as? VariantCell
owner.cellImage.accept(cell?.imageView.image)
.subscribe(onNext: { [weak self] indexPath in
let cell = self?.collectionView.cellForItem(at: indexPath) as? VariantCell
self?.cellImage.accept(cell?.imageView.image)
}).disposed(by: disposeBag)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class CollectionProgressViewController: UIViewController {
}.disposed(by: disposeBag)

tableView.rx.itemSelected
.withUnretained(self)
.subscribe(onNext: { owner, indexPath in
.subscribe(with: self, onNext: { owner, indexPath in
owner.tableView.deselectRow(at: indexPath, animated: true)
}).disposed(by: disposeBag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class CollectionViewController: UIViewController {
.disposed(by: disposeBag)

tableView.rx.itemSelected
.withUnretained(self)
.subscribe(onNext: { owner, indexPath in
.subscribe(with: self, onNext: { owner, indexPath in
owner.tableView.deselectRow(at: indexPath, animated: true)
}).disposed(by: disposeBag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ class AboutViewController: UIViewController {

tableView.rx.itemSelected
.observe(on: MainScheduler.instance)
.withUnretained(self)
.subscribe(onNext: { owner, indexPath in
.subscribe(with: self, onNext: { owner, indexPath in
owner.tableView.deselectRow(at: indexPath, animated: true)
}).disposed(by: disposeBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class CustomTaskViewController: UIViewController {
.disposed(by: disposeBag)

customTaskSection.maxAmountButtonObservable
.withUnretained(self)
.subscribe(onNext: { owner, _ in
.subscribe(with: self, onNext: { owner, _ in
owner.showSelectedItemAlert(
Array(1...20).map { $0.description },
currentItem: owner.currentAmount.value
Expand All @@ -92,16 +91,14 @@ class CustomTaskViewController: UIViewController {

reactor.state
.compactMap { $0.amount }
.withUnretained(self)
.subscribe(onNext: { owner, amount in
.subscribe(with: self, onNext: { owner, amount in
owner.customTaskSection.updateAmount(amount.description)
owner.currentAmount.accept(amount.description)
}).disposed(by: disposeBag)

reactor.state.compactMap { $0.task }
.filter { [weak self] in self?.currentTask.value != $0 }
.withUnretained(self)
.subscribe(onNext: { owner, task in
.subscribe(with: self, onNext: { owner, task in
owner.customTaskSection.setUpViews(task)
owner.currentAmount.accept(task.amount.description)
owner.currentTask.accept(task)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class PreferencesViewController: UIViewController {
.disposed(by: disposeBag)

settingSection.hemisphereButtonObservable
.withUnretained(self)
.subscribe(onNext: { owner, _ in
.subscribe(with: self, onNext: { owner, _ in
owner.showSelectedItemAlert(
Hemisphere.allCases.map { $0.rawValue.localized },
currentItem: owner.currentHemisphere.value
Expand All @@ -79,8 +78,7 @@ class PreferencesViewController: UIViewController {
}).disposed(by: disposeBag)

settingSection.reputationButtonObservable
.withUnretained(self)
.subscribe(onNext: { owner, _ in
.subscribe(with: self, onNext: { owner, _ in
owner.showSelectedItemAlert(
["⭐️", "⭐️⭐️", "⭐️⭐️⭐️", "⭐️⭐️⭐️⭐️", "⭐️⭐️⭐️⭐️⭐️"],
currentItem: owner.currentReputation.value
Expand All @@ -90,8 +88,7 @@ class PreferencesViewController: UIViewController {
}).disposed(by: disposeBag)

settingSection.startingFruitButtonObservable
.withUnretained(self)
.subscribe(onNext: { owner, _ in
.subscribe(with: self, onNext: { owner, _ in
owner.showSelectedItemAlert(
Fruit.allCases.map { $0.rawValue.lowercased().localized },
currentItem: owner.currentFruit.value
Expand All @@ -103,8 +100,7 @@ class PreferencesViewController: UIViewController {
reactor.state
.compactMap { $0.userInfo }
.observe(on: MainScheduler.instance)
.withUnretained(self)
.subscribe(onNext: { owner, userInfo in
.subscribe(with: self, onNext: { owner, userInfo in
owner.settingSection.setUpViews(userInfo)
owner.currentHemisphere.accept(userInfo.hemisphere.rawValue.localized)
owner.currentFruit.accept(userInfo.islandFruit.rawValue.localized)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ class TaskEditViewController: UIViewController {
}.disposed(by: disposeBag)

tableView.rx.itemSelected
.withUnretained(self)
.subscribe(onNext: { owner, indexPath in
owner.tableView.deselectRow(at: indexPath, animated: true)
}).disposed(by: disposeBag)
.subscribe(onNext: { [weak self] indexPath in
self?.tableView.deselectRow(at: indexPath, animated: true)
})
.disposed(by: disposeBag)
}

}
Loading
Loading