Update: Now this works correctly in Xcode - "Outlet Collection" is one of the connection options in Interface Builder that creates something similar:
@IBOutlet var labelCollection: [UILabel]!
While we are waiting for a fix, you can come close to this using a computable property. Say my look has five UILabels that I want in a collection. I still have to declare each, but then I also declare a computed property that collects them:
class MyViewController { @IBOutlet var label1 : UILabel @IBOutlet var label2 : UILabel @IBOutlet var label3 : UILabel @IBOutlet var label4 : UILabel @IBOutlet var label5 : UILabel var labels: UILabel![] { return [label1, label2, label3, label4, label5] }
The view is annoying, but from now on we can treat the labels property as if it were an IBOutletCollection , and we won’t have to change the rest of our code after fixing the error:
override func viewDidLoad() { super.viewDidLoad() for (index, item) in enumerate(self.labels) { item.text = "Label #\(index)" } }
Nate Cook Jun 05 '14 at 17:34 2014-06-05 17:34
source share