Why Swift is introducing a warning for weak captures within nested closures 0 ▲ Swift by Sundell 55 minutes ago · Tech · hide · 0 comments New in Swift 6.4 (which at the time of writing is in beta as part of Xcode 27) is a warning which is emitted when a nested closure performs a weak capture while the parent closure implicitly captures that object as a strong reference.At first glance, that new diagnostic could be a bit puzzling, since it might seem unnecessary to have to specify such a weak capture twice (or, alternatively, move it to the parent closure’s capture list), but it turns out that it’s an incredibly useful new warning that can help us avoid a quite common kind of memory management bug.Take the following code as an example. It performs a nested weak self capture within the closure passed to the call to loadNearbyFriends, while not (explicitly) capturing self at all within the parent closure:@MainActor final class NearbyFriendsViewModel { private(set) var friends = [Friend]() private var timer: Timer? private let service: FriendsService ... @MainActor deinit { timer?.invalidate() } func startScanning() { timer… No comments yet. Log in to reply on the Fediverse. Comments will appear here.