From a9b7d2824ad160c4ab60fd6f51a04c4a6b7d45a8 Mon Sep 17 00:00:00 2001 From: Alexander Cyon Date: Thu, 14 May 2026 07:24:26 +0200 Subject: [PATCH] Capture [weak navigator] instead of [weak self] in viewmodel sinks The sink bodies only call `navigator.next(...)`, so capturing the navigator directly drops the `self?.` chain and makes the closure honest about what it actually needs. Coordinators still use `[weak self]` since their switch branches reach into more of `self`. Co-Authored-By: Claude Opus 4.7 --- Examples/SignUpDemo/Sources/Home/HomeViewModel.swift | 2 +- Examples/SignUpDemo/Sources/Onboarding/SignUpViewModel.swift | 4 ++-- README.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/SignUpDemo/Sources/Home/HomeViewModel.swift b/Examples/SignUpDemo/Sources/Home/HomeViewModel.swift index 9080da7..118a07e 100644 --- a/Examples/SignUpDemo/Sources/Home/HomeViewModel.swift +++ b/Examples/SignUpDemo/Sources/Home/HomeViewModel.swift @@ -25,7 +25,7 @@ public final class HomeViewModel: BaseViewModel< override public func transform(input: Input) -> Output { input.fromView.logoutTrigger - .sink { [weak self] in self?.navigator.next(.logout) } + .sink { [weak navigator] in navigator?.next(.logout) } .store(in: &cancellables) // Greeting is a one-shot publisher — no upstream state changes after diff --git a/Examples/SignUpDemo/Sources/Onboarding/SignUpViewModel.swift b/Examples/SignUpDemo/Sources/Onboarding/SignUpViewModel.swift index db9bcf3..d5fef85 100644 --- a/Examples/SignUpDemo/Sources/Onboarding/SignUpViewModel.swift +++ b/Examples/SignUpDemo/Sources/Onboarding/SignUpViewModel.swift @@ -99,8 +99,8 @@ public final class SignUpViewModel: BaseViewModel< .trackActivity(activity) } .switchToLatest() - .sink { [weak self] user in - self?.navigator.next(.signedUp(user)) + .sink { [weak navigator] user in + navigator?.next(.signedUp(user)) } .store(in: &cancellables) diff --git a/README.md b/README.md index ada5534..e24deeb 100644 --- a/README.md +++ b/README.md @@ -96,8 +96,8 @@ public final class SignUpViewModel: BaseViewModel< .trackActivity(activity) } .switchToLatest() - .sink { [weak self] user in - self?.navigator.next(.signedUp(user)) + .sink { [weak navigator] user in + navigator?.next(.signedUp(user)) } .store(in: &cancellables)