-2

I am trying to convert an old Objective-C code into Swift, however I cannot find the way to make this for loop to work without errors. How could this be converted into Swift?

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
        }
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
SNos
  • 3,430
  • 5
  • 42
  • 92
  • http://stackoverflow.com/questions/35158422/the-and-operators-have-been-deprecated-xcode-7-3 and many other ones – Eric Aya Apr 03 '16 at 17:25
  • The code you posted is already Swift so it isn't clear what you need converted. – rmaddy Apr 03 '16 at 18:06

1 Answers1

0

In your case, this should do it.

for y in 0..<columns {
    for x in 0..<rows {
        // do what you want with x and y
    }
}
xinatanil
  • 1,085
  • 2
  • 13
  • 23