Skip to content

Commit 846929e

Browse files
authored
Merge pull request #26 from simla-tech/task-90656
Fixes #23 - Add weak reference for objects
2 parents c694280 + c5b633c commit 846929e

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

Example/Source/ViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ class ViewController: UIViewController {
107107
fastisController.maximumDate = Calendar.current.date(byAdding: .month, value: 3, to: Date())
108108
fastisController.allowToChooseNilDate = true
109109
fastisController.shortcuts = [.today, .lastWeek, .lastMonth]
110-
fastisController.doneHandler = { newValue in
111-
self.currentValue = newValue
110+
fastisController.doneHandler = { [weak self] newValue in
111+
self?.currentValue = newValue
112112
}
113113
fastisController.present(above: self)
114114
}
@@ -120,8 +120,8 @@ class ViewController: UIViewController {
120120
fastisController.initialValue = self.currentValue as? Date
121121
fastisController.maximumDate = Date()
122122
fastisController.shortcuts = [.today, .yesterday, .tomorrow]
123-
fastisController.doneHandler = { newDate in
124-
self.currentValue = newDate
123+
fastisController.doneHandler = { [weak self] newDate in
124+
self?.currentValue = newDate
125125
}
126126
fastisController.present(above: self)
127127
}

Sources/Views/Controller.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ open class FastisController<Value: FastisValue>: UIViewController, JTACMonthView
515515
header.applyConfig(self.config.monthHeader)
516516
header.configure(for: range.start)
517517
if self.privateSelectMonthOnHeaderTap, Value.mode == .range {
518-
header.tapHandler = {
518+
header.tapHandler = { [weak self, weak calendar] in
519+
guard let self, let calendar else { return }
519520
var fromDate = range.start.startOfMonth(in: self.config.calendar)
520521
var toDate = range.start.endOfMonth(in: self.config.calendar)
521522
if let minDate = self.minimumDate {

Sources/Views/ShortcutContainerView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ final class ShortcutContainerView<Value: FastisValue>: UIView {
7878
itemView.tag = i
7979
itemView.name = item.name
8080
itemView.isSelected = item == self.selectedShortcut
81-
itemView.tapHandler = {
82-
self.onSelect?(item)
81+
itemView.tapHandler = { [weak self] in
82+
self?.onSelect?(item)
8383
}
8484
self.stackView.addArrangedSubview(itemView)
8585
}

Sources/Views/ShortcutItemView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ final class ShortcutItemView: UIView {
1919
card.cornerRadius = self.config.cornerRadius
2020
card.animation = self.config.tapAnimation
2121
card.setShadow(self.config.shadow)
22-
card.tapHandler = {
23-
self.tapHandler?()
22+
card.tapHandler = { [weak self] in
23+
self?.tapHandler?()
2424
}
2525
card.translatesAutoresizingMaskIntoConstraints = false
2626
return card

0 commit comments

Comments
 (0)