Skip to content

Commit dfaef13

Browse files
committed
Fix static analyzer issues and a crash when the user has dismissed everything
1 parent 76529f5 commit dfaef13

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

SLToastKit/SLToastKit/SLToast.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
8686
struct SLToastKeys keys = SLToastKeys;
8787

8888
NSString *toastId = SLTypeNonEmptyStringOrNil(dictionary[keys.identifier]);
89+
if (!toastId)
90+
return nil;
91+
8992
NSString *title = SLTypeStringOrNil(dictionary[keys.title]);
9093
NSString *subtitle = SLTypeStringOrNil(dictionary[keys.subtitle]);
9194
UIImage *image = SLTypeImageOrNil(dictionary[keys.image]);
@@ -105,6 +108,8 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
105108
subtitle:subtitle
106109
image:image
107110
duration:duration];
111+
if (self)
112+
self.status = status;
108113

109114
return self;
110115
}

SLToastKit/SLToastKit/SLToastManager.m

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,6 @@ - (void)dealloc
8181
[_nagLimitTimer invalidate];
8282
_nagLimitTimer = nil;
8383
#endif
84-
85-
// Just in case consumers retained their toasts and need status updates...
86-
87-
for (SLToast *toast in _store)
88-
{
89-
if (toast.status != SLToastStatusQueued
90-
&& toast.status != SLToastStatusFinished
91-
&& toast.status != SLToastStatusSkipped)
92-
{
93-
toast.status = SLToastStatusUnknown;
94-
}
95-
}
9684
}
9785

9886
- (NSUInteger)totalToastCount
@@ -207,22 +195,28 @@ - (nullable SLToast *)pullNext
207195

208196
if (self.store.count)
209197
{
210-
NSMutableIndexSet *toastsToRemove = [NSMutableIndexSet indexSet];
198+
NSMutableArray<SLToast *> *toastsToRemove = [[NSMutableArray alloc] init];
199+
200+
//NSMutableIndexSet *toastsToRemove = [NSMutableIndexSet indexSet];
211201
[self.store enumerateObjectsUsingBlock:^(SLToast * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
212-
if (toast.status != SLToastStatusSkipped)
202+
if (toast.status == SLToastStatusSkipped)
203+
{
204+
[toastsToRemove addObject:obj];
205+
return; // keep iterating until we find one that isn't skipped
206+
}
207+
else
213208
{
214-
toast = obj;
215-
[toastsToRemove addIndex:idx]; // popping this (unskipped) toast from the queue
209+
toast = [obj copy];
210+
[toastsToRemove addObject:obj];
216211
*stop = YES;
217212
return;
218213
}
219-
[toastsToRemove addIndex:idx];
220214
}];
221215

222216
if (!toastsToRemove.count)
223217
return toast;
224218

225-
[self.store removeObjectsAtIndexes:toastsToRemove];
219+
[self.store removeObjectsInArray:toastsToRemove];
226220
}
227221

228222
return toast;

SLToastKit/SLToastKit/SLToastView.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ NS_ASSUME_NONNULL_BEGIN
1616

1717
@interface SLToastView : UIView
1818

19-
+ (instancetype)showToastInView:(UIView *)parentView
20-
toast:(SLToast *)toast;
19+
+ (nullable instancetype)showToastInView:(UIView *)parentView
20+
toast:(SLToast *)toast;
2121

22-
+ (instancetype)showToastInWindow:(UIWindow *)parentWindow
23-
statusBarFrame:(CGRect)statusBarFrame
24-
toast:(SLToast *)toast;
22+
+ (nullable instancetype)showToastInWindow:(UIWindow *)parentWindow
23+
statusBarFrame:(CGRect)statusBarFrame
24+
toast:(SLToast *)toast;
2525

2626
- (BOOL)showToast:(SLToast *)toast;
2727

SLToastKit/SLToastKit/SLToastView.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ + (instancetype)showToastInView:(UIView *)parentView
5050
[parentView addSubview:toastView];
5151

5252
NSTimeInterval duration = toast.duration;
53-
if (duration > 0)
53+
if (duration >= 0)
5454
{
5555
__weak SLToastView *wView = toastView;
5656
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@@ -82,7 +82,7 @@ + (instancetype)showToastInWindow:(UIWindow *)parentWindow
8282
[parentWindow addSubview:toastView];
8383

8484
NSTimeInterval duration = toast.duration;
85-
if (duration > 0)
85+
if (duration >= 0)
8686
{
8787
__weak SLToastView *wView = toastView;
8888
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@@ -110,7 +110,7 @@ - (BOOL)showToast:(SLToast *)toast
110110
toast.status = SLToastStatusShowing;
111111

112112
NSTimeInterval duration = toast.duration;
113-
if (duration > 0)
113+
if (duration >= 0)
114114
{
115115
__weak SLToastView *wView = self;
116116
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

0 commit comments

Comments
 (0)