title: Swift: Recursively cycle through all subviews to find a specific class and append to an array
body: <p>Having a devil of a time trying to figure this out. I asked a similar question here: <a href="https://stackoverflow.com/questions/32151637/swift-get-all-subviews-of-a-specific-type-and-add-to-an-array">Swift: Get all subviews of a specific type and add to an array</a></p>
  
  <p>While this works, I realized there are many subviews and sub-sub views, and so I need a function that starts at the main UIView, cycles through all the subviews (and their subviews until there aren't any left) and adds it to an array for a custom button class which I have named CheckCircle.</p>
  
  <p>Essentially I'd like to end up with an array of CheckCircles which constitute all the CheckCircles added to that view programmatically.</p>
  
  <p>Any ideas? Here's what I've been working on. It doesn't seem to be appending any Checkcircles to the array:</p>
  
  <pre><code>    func getSubviewsOfView(v:UIView) -&gt; [CheckCircle] {
          var circleArray = [CheckCircle]()
          // Get the subviews of the view
  
          var subviews = v.subviews
  
          if subviews.count == 0 {
              return circleArray
          }
  
          for subview : AnyObject in subviews{
    if let viewToAppend = subview as? CheckCircle {
          circleArray.append(viewToAppend as CheckCircle)
        }
              getSubviewsOfView(subview as! UIView)
          }
          return circleArray
      }
  </code></pre>