Skip to content

Commit 7b3c87e

Browse files
authored
Merge pull request #201 from faimin/master
fix Swift中LEEAlertConfig提前释放问题
2 parents b1c505a + 23847fe commit 7b3c87e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

LEEAlert/LEEAlert.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#define DEFAULTBORDERWIDTH (1.0f / [[UIScreen mainScreen] scale] + 0.02f)
3030
#define VIEWSAFEAREAINSETS(view) ({UIEdgeInsets i; if(@available(iOS 11.0, *)) {i = view.safeAreaInsets;} else {i = UIEdgeInsetsZero;} i;})
3131

32+
NS_INLINE void lee_cleanupFunc(__strong dispatch_block_t *block) {
33+
(*block)();
34+
}
35+
3236
#pragma mark - ===================配置模型===================
3337

3438
typedef NS_ENUM(NSInteger, LEEBackgroundStyle) {
@@ -4048,13 +4052,18 @@ - (nonnull instancetype)init
40484052

40494053
self.isShowing = NO;
40504054

4051-
__weak typeof(self) weakSelf = self;
4055+
__block typeof(self) strongSelf = self;
40524056

40534057
self.config.modelFinishConfig = ^{
40544058

4055-
__strong typeof(weakSelf) strongSelf = weakSelf;
4059+
__attribute__((cleanup(lee_cleanupFunc), unused)) __auto_type x = ^{
4060+
// break circular reference after leaving the scope.
4061+
strongSelf = nil;
4062+
};
40564063

4057-
if (!strongSelf) return;
4064+
if (!strongSelf) {
4065+
return;
4066+
}
40584067

40594068
if ([LEEAlert shareManager].queueArray.count) {
40604069

LEEAlertSwiftDemo/LEEAlertSwiftDemo/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ViewController: UIViewController {
1818
super.touchesBegan(touches, with: event)
1919

2020
let alert = LEEAlert.alert()
21-
_ = alert.config
21+
.config
2222
.leeTitle("标题")
2323
.leeContent("内容")
2424
.leeAction("确认", {

0 commit comments

Comments
 (0)