Skip to content

Commit

Permalink
Fix static analyzer issues and a crash when the user has dismissed ev…
Browse files Browse the repository at this point in the history
…erything
  • Loading branch information
grgcombs committed Jan 6, 2017
1 parent 76529f5 commit dfaef13
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
5 changes: 5 additions & 0 deletions SLToastKit/SLToastKit/SLToast.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
struct SLToastKeys keys = SLToastKeys;

NSString *toastId = SLTypeNonEmptyStringOrNil(dictionary[keys.identifier]);
if (!toastId)
return nil;

NSString *title = SLTypeStringOrNil(dictionary[keys.title]);
NSString *subtitle = SLTypeStringOrNil(dictionary[keys.subtitle]);
UIImage *image = SLTypeImageOrNil(dictionary[keys.image]);
Expand All @@ -105,6 +108,8 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
subtitle:subtitle
image:image
duration:duration];
if (self)
self.status = status;

return self;
}
Expand Down
30 changes: 12 additions & 18 deletions SLToastKit/SLToastKit/SLToastManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,6 @@ - (void)dealloc
[_nagLimitTimer invalidate];
_nagLimitTimer = nil;
#endif

// Just in case consumers retained their toasts and need status updates...

for (SLToast *toast in _store)
{
if (toast.status != SLToastStatusQueued
&& toast.status != SLToastStatusFinished
&& toast.status != SLToastStatusSkipped)
{
toast.status = SLToastStatusUnknown;
}
}
}

- (NSUInteger)totalToastCount
Expand Down Expand Up @@ -207,22 +195,28 @@ - (nullable SLToast *)pullNext

if (self.store.count)
{
NSMutableIndexSet *toastsToRemove = [NSMutableIndexSet indexSet];
NSMutableArray<SLToast *> *toastsToRemove = [[NSMutableArray alloc] init];

//NSMutableIndexSet *toastsToRemove = [NSMutableIndexSet indexSet];
[self.store enumerateObjectsUsingBlock:^(SLToast * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (toast.status != SLToastStatusSkipped)
if (toast.status == SLToastStatusSkipped)
{
[toastsToRemove addObject:obj];
return; // keep iterating until we find one that isn't skipped
}
else
{
toast = obj;
[toastsToRemove addIndex:idx]; // popping this (unskipped) toast from the queue
toast = [obj copy];
[toastsToRemove addObject:obj];
*stop = YES;
return;
}
[toastsToRemove addIndex:idx];
}];

if (!toastsToRemove.count)
return toast;

[self.store removeObjectsAtIndexes:toastsToRemove];
[self.store removeObjectsInArray:toastsToRemove];
}

return toast;
Expand Down
10 changes: 5 additions & 5 deletions SLToastKit/SLToastKit/SLToastView.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ NS_ASSUME_NONNULL_BEGIN

@interface SLToastView : UIView

+ (instancetype)showToastInView:(UIView *)parentView
toast:(SLToast *)toast;
+ (nullable instancetype)showToastInView:(UIView *)parentView
toast:(SLToast *)toast;

+ (instancetype)showToastInWindow:(UIWindow *)parentWindow
statusBarFrame:(CGRect)statusBarFrame
toast:(SLToast *)toast;
+ (nullable instancetype)showToastInWindow:(UIWindow *)parentWindow
statusBarFrame:(CGRect)statusBarFrame
toast:(SLToast *)toast;

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

Expand Down
6 changes: 3 additions & 3 deletions SLToastKit/SLToastKit/SLToastView.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ + (instancetype)showToastInView:(UIView *)parentView
[parentView addSubview:toastView];

NSTimeInterval duration = toast.duration;
if (duration > 0)
if (duration >= 0)
{
__weak SLToastView *wView = toastView;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -82,7 +82,7 @@ + (instancetype)showToastInWindow:(UIWindow *)parentWindow
[parentWindow addSubview:toastView];

NSTimeInterval duration = toast.duration;
if (duration > 0)
if (duration >= 0)
{
__weak SLToastView *wView = toastView;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -110,7 +110,7 @@ - (BOOL)showToast:(SLToast *)toast
toast.status = SLToastStatusShowing;

NSTimeInterval duration = toast.duration;
if (duration > 0)
if (duration >= 0)
{
__weak SLToastView *wView = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
Expand Down

0 comments on commit dfaef13

Please sign in to comment.