title: Make an object/image appear and disappear randomly in Xcode
body: <p>I have to make a target appear and disappear randomly, e.g. in a space of 20 seconds but want to fix the flash first. The object is inserted programmatically and is just a png with collision. When the ball hits it, it disappears and the score is added. This part already works. Current code below</p>
  
  <p>Spawn the enemy(is part of the function for the other 4 enemies) </p>
  
  <pre><code>let enemy1 = UIImageView(image: nil)
          enemy1.image = UIImage(named: "enemy2.png")
          enemy1.frame = CGRect(x: w*0.85, y: h*0.035, width: w*0.12, height: h*0.22)
          self.view.addSubview(enemy1)
  </code></pre>
  
  <p>Add 1 to score when hit:</p>
  
  <pre><code> collisionBehaviour = UICollisionBehavior(items:[enemy1])
      dynamicAnimator.addBehavior(collisionBehaviour)
  
      collisionBehaviour.action = {
  
          for boulderView in self.bouldersArray{
              if boulderView.frame.intersects(enemy1.frame){
                  //enemy1.removeFromSuperview()
                  if enemy1.superview != nil{
                          self.scoreCount += 1
                          self.scoreCountLabel.text = "Score: \(self.scoreCount)"
                          enemy1.removeFromSuperview()
                  }
              }
          }
      }
  </code></pre>
  
  <p>It's very hardcoded, please don't fix that. Tried an <code>if</code> statement to make it appear and disappear from subview, but it didn't work at all, just failed madly.</p>