Last active
April 28, 2021 10:58
-
-
Save MMnasrabadi/955bfb0ea979ddeb01f4418adafa0e05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clean remore memory leak | |
protocol Weakifiable: class { } | |
extension NSObject: Weakifiable {} | |
extension Weakifiable { | |
func weakify<T, Z>(_ code: @escaping (Self, T) -> Z) -> (T) -> Z? { | |
return { [weak self] data in | |
guard let self = self else { return nil} | |
return code(self, data) | |
} | |
} | |
func weakify<T>(_ code: @escaping (Self, T) -> Void) -> (T) -> Void { | |
return { [weak self] data in | |
guard let self = self else { return } | |
code(self, data) | |
} | |
} | |
func weakify<Z>(_ code: @escaping (Self) -> Z) -> () -> Z? { | |
return { [weak self] in | |
guard let self = self else { return nil} | |
return code(self) | |
} | |
} | |
func weakify(_ code: @escaping (Self) -> Void) -> () -> Void { | |
return { [weak self] in | |
guard let self = self else { return } | |
code(self) | |
} | |
} | |
} |
- in RxSwift 6.0.0 use
.withUnretained(self)
autoweakify
by rx
- in weakify by return :
use.CompactMap
instead of.map
because is optional
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
old use weak:
var returnCellText: (String) -> ()
use weakify
-- or
// instead of