Skip to content

Commit

Permalink
Use weak self reference in .sink instead of force casting
Browse files Browse the repository at this point in the history
  • Loading branch information
terwanerik committed Mar 29, 2022
1 parent c194d86 commit dcdb313
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MMMLoadable.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Pod::Spec.new do |s|

s.name = "MMMLoadable"
s.version = "1.7.0"
s.version = "1.7.1"
s.summary = "A simple model for async calculations"
s.description = "#{s.summary}."
s.homepage = "https://github.com/mediamonks/#{s.name}"
Expand Down
9 changes: 7 additions & 2 deletions Sources/MMMLoadable/MMMLoadable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//

import Foundation
import MMMCommonCore

#if SWIFT_PACKAGE
@_exported import MMMLoadableObjC
Expand All @@ -23,8 +24,12 @@ extension MMMPureLoadableProtocol {
/// - Returns: The observer, you usually want to store this outside of the scope, e.g.
/// in a private property so it doesn't deallocate right away.
public func sink(_ block: @escaping (Self) -> Void) -> MMMLoadableObserver? {
return MMMLoadableObserver(loadable: self) { loadable in
block(loadable as! Self)
return MMMLoadableObserver(loadable: self) { [weak self] _ in
guard let self = self else {
assertionFailure("\(MMMTypeName(Self.self)) was lost inside the observer callback?")
return
}
block(self)
}
}
}

0 comments on commit dcdb313

Please sign in to comment.