-2

我正在尝试将旧的 Objective-C 代码转换为 Swift,但是我找不到使这个 for 循环正常工作的方法。这怎么能转换成 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
        }
4

1 回答 1

0

在你的情况下,这应该这样做。

for y in 0..<columns {
    for x in 0..<rows {
        // do what you want with x and y
    }
}
于 2016-04-03T18:10:43.157 回答