2016-04-03 5 views
-2

Ich versuche, einen alten Objective-C-Code in Swift zu konvertieren, aber ich kann nicht den Weg finden, diese For-Schleife ohne Fehler zu arbeiten. Wie könnte dies in Swift umgewandelt werden?Convert for Schleife von 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 und viele andere, die – Moritz

+0

Der Code, den Sie ist bereits gebucht Swift so es isn Klar, was du konvertieren willst. – rmaddy

Antwort

0

In Ihrem Fall sollte dies tun.

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