2016-04-03 49 views
-2

我想將一箇舊的Objective-C代碼轉換成Swift,但是我找不到讓循環無錯地工作的方法。這怎麼可能轉換成Swift?轉換爲Objective-C的循環

for var y = 0; y < columns; y++ { //C-style for statement is deprecated and will be removed in a future version of Swift 
      xPos = 0.0 
      for var x = 0; x < rows; x++ { //C-style for statement is deprecated and will be removed in a future version of Swift 
       var rect: CGRect = CGRectMake(xPos, yPos, width, height) 
       var cImage: CGImageRef = CGImageCreateWithImageInRect(image.CGImage, rect)! 
       var dImage: UIImage = UIImage(CGImage: cImage) 
       var imageView: UIImageView = UIImageView(frame: CGRectMake(x * width, y * height, width, height)) 
       imageView.image = dImage 
       imageView.layer.borderColor = UIColor.blackColor().CGColor 
       imageView.layer.borderWidth = 1.0 
       //self.view!.addSubview(imageView) 
       arrayImages.append(dImage) 
       xPos += width 
      } 
      yPos += height 
     } 
+0

http://stackoverflow.com/questions/35158422/the-and-operators-have-been-deprecated-xcode-7-3和許多其他的 – Moritz

+0

您發佈的代碼已經是斯威夫特所以它不是不清楚你需要轉換的東西。 – rmaddy

回答

0

在你的情況,這應該做到這一點。

for y in 0..<columns { 
    for x in 0..<rows { 
     // do what you want with x and y 
    } 
}