How can I add make an array for all of my IBOutlets?
Open the Assistant Editor, right-click and drag from one of your UIProgressView's or just drag from its "Referencing Outlet Collections" to the code file.
Insert outlet collection
Then you can drag from your swift file's @IBOutlet to the rest of your UIProgressView's. Add view to collection
Put multiple UILabels into an array
As rmaddy mentioned in a comment you can use an outlet collection:
@IBOutlet private var labels: [UILabel]!
Then in your storyboard labels
will show up under Outlet Collections
when right-clicking your ViewController
, and you can link multiple labels:
How to make IBOutlets out of an array of objects?
It is possible, it’s called outlet collection. This is the way to define an outlet collection:
@property(retain) IBOutletCollection(UIImageView) NSArray *images;
Now you can stick more than one object into the outlet in the Interface Builder, the array will be created for you when the interface is loaded.
Warning whilst putting IBOutlet buttons in an array
Either use lazy var
declaration for allSpaces
or make an @IBOutlet
collection:
lazy var allSpaces = [oneOne,twoOne,threeOne,oneTwo,twoTwo,threeTwo,oneThree,twoThree,threeThree]
or:
@IBOutlet weak var buttons: [UIButton]! // Connect your outlets here.
Array of IBOutlets in Swift
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var countryField: UITextField!
@IBOutlet weak var cityField: UITextField!
...
let array = [emailField, countryField, cityField]
Have a look at the documentation on collection types
edit: you can split the declaration/init of that array
// outside any method
var array = [UITextField]?
// in viewDidLoad
self.array = [emailField, countryField, cityField]
Related Topics
How to Prevent a Remote Notification from Being Displayed
How to Set the Rootviewcontroller with Swift, iOS 7
Alert When New Version of iOS App Is Available
Will Push Notification Still Work After Ownership Transfer in Itunesconnect
Cncopycurrentnetworkinfo with iOS 13
Gamecenter iOS 9 Gamecenter Gklocalplayerlistener Methods Not Called
Uisearchcontroller Disable Cancel Uibarbuttonitem
Nstask or Equivalent for Iphone
How to Change Color of Text Strings Inside Uitextview in Swift3
Creating an Image Format with an Unknown Type Is an Error Objective-C Xcode 8
Phonegap on iOS with Absolute Path Urls for Assets
JSON Parsing Using Nsjsonserialization in iOS
Firebase Dynamic Link Always Goes to App Store Url Even If the App Is Installed
Nsinteralinconsistencyexception - Uikeyboardlayoutalignmentview
Warning in Custom Map Annotations Iphone
Swift - Downcast Nsurlresponse to Nshttpurlresponse in Order to Get Response Code