Skip to content

Commit 3c2ecd5

Browse files
etoledompinarol
andauthored
Remove strong references of self in closures (#765)
Co-authored-by: Pinar Olguc <[email protected]>
1 parent 08cb2a5 commit 3c2ecd5

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

Demo/Demo/Gravatar-Demo/DemoQuickEditorViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,18 @@ final class DemoQuickEditorViewController: UIViewController {
284284

285285
lazy var schemeToggle: UISegmentedControl = {
286286
let control = UISegmentedControl(items: [
287-
UIAction.init(title: "System") { _ in self.customColorScheme = .unspecified },
288-
UIAction.init(title: "Light") { _ in self.customColorScheme = .light },
289-
UIAction.init(title: "Dark") { _ in self.customColorScheme = .dark },
287+
UIAction.init(title: "System") { [weak self] _ in self?.customColorScheme = .unspecified },
288+
UIAction.init(title: "Light") { [weak self] _ in self?.customColorScheme = .light },
289+
UIAction.init(title: "Dark") { [weak self] _ in self?.customColorScheme = .dark },
290290
])
291291
control.selectedSegmentIndex = 0
292292
return control
293293
}()
294294

295295
lazy var imageEditorToggle: UISegmentedControl = {
296296
let control = UISegmentedControl(items: [
297-
UIAction.init(title: "Default Image Editor") { _ in self.useCustomImageEditor = false },
298-
UIAction.init(title: "Custom Image Editor") { _ in self.useCustomImageEditor = true },
297+
UIAction.init(title: "Default Image Editor") { [weak self] _ in self?.useCustomImageEditor = false },
298+
UIAction.init(title: "Custom Image Editor") { [weak self] _ in self?.useCustomImageEditor = true },
299299
])
300300
control.selectedSegmentIndex = 0
301301
return control

Sources/GravatarUI/QuickEditor/QuickEditorConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import UIKit
22

3-
public class QuickEditorConfiguration {
3+
public struct QuickEditorConfiguration {
44
let interfaceStyle: UIUserInterfaceStyle
55
let customImageEditorProvider: CustomImageEditorControllerProvider?
66

Sources/GravatarUI/QuickEditor/QuickEditorViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ final class QuickEditorViewController<ImageEditor: ImageEditorView>: UIViewContr
1919

2020
private lazy var isPresented: Binding<Bool> = Binding {
2121
true
22-
} set: { isPresented in
22+
} set: { [weak self] isPresented in
2323
Task { @MainActor in
2424
guard !isPresented else { return }
25-
self.dismiss(animated: true)
26-
self.onDismiss?()
25+
self?.dismiss(animated: true)
26+
self?.onDismiss?()
2727
}
2828
}
2929

@@ -87,7 +87,6 @@ final class QuickEditorViewController<ImageEditor: ImageEditorView>: UIViewContr
8787

8888
override func viewDidLoad() {
8989
super.viewDidLoad()
90-
9190
quickEditor.willMove(toParent: self)
9291
addChild(quickEditor)
9392
view.addSubview(quickEditor.view)
@@ -111,7 +110,8 @@ final class QuickEditorViewController<ImageEditor: ImageEditorView>: UIViewContr
111110

112111
func updateDetents() {
113112
if let sheet = sheetPresentationController {
114-
sheet.animateChanges {
113+
sheet.animateChanges { [weak self] in
114+
guard let self else { return }
115115
sheet.detents = QEDetent.detents(
116116
for: scopeOption,
117117
intrinsicHeight: sheetHeight,

Sources/GravatarUI/SwiftUI/AvatarPicker/AvatarPickerViewModel.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ class AvatarPickerViewModel: ObservableObject {
125125
// Determine if the warning should be displayed
126126
selectedAvatarURL == nil && loadedAvatarCount > 0
127127
}
128-
.assign(to: \.shouldDisplayNoSelectedAvatarWarning, on: self)
128+
.sink { [weak self] shouldShowWarning in
129+
self?.shouldDisplayNoSelectedAvatarWarning = shouldShowWarning
130+
}
129131
.store(in: &cancellables)
130132

131133
$profileResult.sink { [weak self] profileResult in

0 commit comments

Comments
 (0)