What is an IBOutletCollection in iOS??
When we try to create a new IBOutlet or new IBAction, a third option shows up named IBOutletCollection. I always wondered what it is, but never got a chance to check that out. If you already know what it is, then please skip this article.
Published in
3 min readAug 23, 2017
As the name says, an IBOutletCollection
is a collection of IBOutlets
. It can either be a collection of UI elements.
An IBOutletCollection
of UIButton in code will look like this :
@IBOutlet var starButtons: [UIButton]!
It will be an array of UIButton
objects.
There are two rather curious things to note about an IBOutletCollection
array:
- Its order is not necessarily guaranteed. The order of an outlet collection appears to be roughly the order in which their connections are established in Interface Builder. However, there are numerous reports of that order changing across versions of Xcode, or as a natural consequence of version control. Nonetheless, having code rely on a fixed order is strongly discouraged.
- No matter what type is declared for the property, an
IBOutletCollection
is always anNSArray