Skip to content
Permalink
Browse files

feat: improved Counter syntax

  • Loading branch information...
jdev7 committed Oct 12, 2017
1 parent 8c297ad commit 204f48c54a6246a7c9017b836de03ad41ea736aa
Showing with 11 additions and 16 deletions.
  1. +11 −16 Counter/Classes/Counter.swift
@@ -99,27 +99,22 @@ public class Counter{
}

fileprivate func notifyDelegateWill(oldValue: Int, newValue: Int) {
if let delegate = delegate {
milestones.forEach{ milestone in
guard !self.handledMilestones.contains(milestone) else { return }
if newValue >= milestone {
delegate.counter(self, willReachValue: milestone)
}
}
guard let delegate = delegate else { return }
milestones.forEach{ milestone in
guard !self.handledMilestones.contains(milestone), newValue >= milestone else { return }
delegate.counter(self, willReachValue: milestone)
}
}

fileprivate func notifyDelegate() {
if let delegate = delegate {
delegate.counter(self, didChangeValue: value)
milestones.forEach{ milestone in
guard !self.handledMilestones.contains(milestone) else { return }
if value >= milestone {
delegate.counter(self, hasReachedValue: milestone)
self.handledMilestones.insert(milestone)
}
}
guard let delegate = delegate else { return }
delegate.counter(self, didChangeValue: value)
milestones.forEach{ milestone in
guard !self.handledMilestones.contains(milestone), value >= milestone else { return }
delegate.counter(self, hasReachedValue: milestone)
self.handledMilestones.insert(milestone)
}

}
}

0 comments on commit 204f48c

Please sign in to comment.
You can’t perform that action at this time.