I am having trouble creating an outlet collection in Xcode 6. Outlet collections in Xcode 6 now function as regular IBOutlets, and you use the same @IBOutlet attribute to de
This is under the Xcode 6 beta known issues: "Interface Builder does not support declaring outlet collections in Swift classes. (15607242)"
Nate Cook's answer is correct for attaching outlets, but not outlet collections. Hopefully in the next Xcode 6 beta release this issue will be resolved.
It is strange, I did IBOutlet with swift and it works for a while, Just realize it stop working and find out something get broke in last release of xcode beta where it is not working.
You've got it right, you just need to define the array more formally:
@IBOutlet var cardButtons: Array<UIButton>
Now you'll be able to connect the buttons from IB.
The above should work, but still doesn't in Xcode 6 beta 3. A workaround is to use an NSArray
until Xcode and Swift can handle this properly:
class ViewController: UIViewController {
@IBOutlet strong var labels: NSArray!
override func viewDidLoad() {
super.viewDidLoad()
for label in self.labels as [UILabel] {
label.textColor = UIColor.redColor()
}
}
}
In seed 3 of Xcode 6, the following syntax works:
@IBOutlet strong var cardButtons: NSArray?
Note the following:
You have to use strong
because @IBOutlet is weak by default, and since the array is not in the interface, it will vanish before you have a chance to use it.
You have to use NSArray because you can't mark Array as strong.
Knowing the contained type is now up to you, of course.
Note also that this is not the syntax advertised by the docs or by Xcode itself when you control-drag to form an outlet collection. I can't help that; using that syntax causes a seg fault, so clearly something else is needed, at least for now.