Skip to content

Instantly share code, notes, and snippets.

@adajos
Last active August 29, 2015 14:24
Show Gist options
  • Save adajos/8ba002e738dfcbfacafc to your computer and use it in GitHub Desktop.
Save adajos/8ba002e738dfcbfacafc to your computer and use it in GitHub Desktop.
Swift's Enumerate Awesomeness
//: Playground - noun: a place where people can play
import UIKit
let scaleValues = ["10 feet", "100 feet", "100 yards", "400 yards", "800 yard", "1200 yards", "1 mile"]
var scaleLabels = [UILabel]()
for (scaleValueIndex, scaleValue) in scaleValues.enumerate() {
var label = UILabel(frame: CGRectMake((CGFloat(scaleValueIndex) + 1 * 100), 10, 100, 25))
label.text = scaleValue
label.backgroundColor = UIColor.yellowColor()
label.textColor = scaleValueIndex % 2 == 0 ? UIColor.redColor() : UIColor.blackColor()
scaleLabels.append(label)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment