title: How to declare for loop in swift?
body: <p>I am facing some problem in writing a for loop in Swift.
  Can anybody guess the problem in this</p>
  
  <pre><code> var sublayers : Array &lt;AnyObject&gt;= [self.previewLayer.sublayers]
          var subLayersCount: NSInteger = sublayers.count, currentSublayer = 0
          var featuresCount :NSInteger = features.count, currentFeature = 0;
  
          CATransaction.begin()
          CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
          var layerTemp : CALayer = CALayer()
          for layerTemp  in sublayers{
              if(layerTemp.name  == "FaceLayer"){
                  layerTemp.hidden = true
              }
  </code></pre>
  
  <p>I am trying to check the layers in sublayers. 
  <code>layertemp</code> is of <code>CAlayer</code> and <code>sublayers</code> is of <code>AnyObject</code>.</p>
  
  <p>It gives me an error:
  <code>Constant layerTemp is inferred to be of AnyObject which is unexpected.</code></p>
  
  <p>Can anybody shed some light over this.</p>
  
  <p>Equivalent code in obj-c is:</p>
  
  <pre><code>NSArray *sublayers = [NSArray arrayWithArray:[self.previewLayer sublayers]];
  NSInteger sublayersCount = [sublayers count], currentSublayer = 0;
  NSInteger featuresCount = [features count], currentFeature = 0;
  
  [CATransaction begin];
  [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
  
  // hide all the face layers
  for ( CALayer *layer in sublayers ) {
      if ( [[layer name] isEqualToString:@"FaceLayer"] )
          [layer setHidden:YES];
  }   
  </code></pre>