title: Swift4: How to resolve "Fatal error: Can't form Range with upperBound < lowerBound"? (duration time delay in UI)
body: <p>I try to close the menu animatedly using animation, 
  I decided to reduce the size of the <code>UIScrollView</code> on button press when size reduces up to my desired value, then I hide it.</p>
  
  <p>to accomplish the task according to my desired user interface at some points, I had used the "time delay function" (300 milisec given) </p>
  
  <p>everything goes well: if I don't press the button again and again until time limit reached </p>
  
  <p>Error occurred: when i press button again and again before  with in 300 milisec</p>
  
  <pre><code>func disAppearBlanceMenu(){
      let x1 = btn_addBalance.clickableimg.frame.midX
      let y1 = btn_addBalance.clickableimg.frame.maxY
  
      UIView.animate(withDuration: 0.3) {
          self.BalanceMenu.scrollview.frame = CGRect(x: x1 - 150, y: y1 + 20, width: 200, height: 20)
      }
      time.delay(milliSec: 300) {
          self.BalanceMenu.triangle.isHidden = true
          self.BalanceMenu.scrollview.isHidden = true
          for i in 0...(self.BalanceMenuBtn.count - 1) {
              self.BalanceMenuBtn[i].imag.removeFromSuperview()
              self.BalanceMenuBtn[i].button.removeFromSuperview()
          }
          self.BalanceMenuBtn.removeAll()
  
      }
      displayBalanceMenu = true
  }
  </code></pre>
  
  <p>Where</p>
  
  <pre><code>class time {
      static func delay(milliSec:Int, code: @escaping () -&gt; Void ) {
          let deadline = DispatchTime.now() + .milliseconds(milliSec)
          DispatchQueue.main.asyncAfter(deadline: deadline) {
              code()
          }
      }
  }
  </code></pre>
  
  <p>The error occurs here:</p>
  
  <pre><code>time.delay(milliSec: 300) {
  </code></pre>
  
  <p>It says</p>
  
  <blockquote>
    <p>'Thread 1: Fatal error: Can't form Range with upperBound &lt; lowerBound'</p>
  </blockquote>