Swift put multiple IBOutlets in an Array
I made these (marked with red border) IBOutlets using ctrl + drag
But i don’t like to have the exact same line 9 times (DRY)
How do i put these IBOutlets in an Array?
- Swift - Get data from Alamofire POST request
- Calling C++ from Swift - what is the equivalent of std::vector<T>
- UITableView set a web view and a button outside the web view as background
- Swift: Could not cast value of type 'UITableViewCell' to a custom cell class
- Save data in Keychain only accessible with Touch ID in Swift 3
- Set local notification for everyday at midnight
3 Solutions Collect From Internet About “Swift put multiple IBOutlets in an Array”
you can define a generic outlet collection in Swift like this:
@IBOutlet var collectionOfViews: Array<UIView>?
or for e.g.
@IBOutlet var collectionOfButtons: Array<UIButton>?
you can find your collections under the Outlet Collections group as usually are in the File’s Owner:
it would look on my console after connecting 5 random buttons:
Solution here Swift – IBOutletCollection equivalent
@IBOutlet var objectCollection: [Object]
Start with the two view pane where you see both your code and the storyboard. When you make your first IBOutlet connection from the UI to your code, just look carefully at the Connection drop down field and select the option called “Outlet Collection”. This will automatically create an array of IBOutlets. Next just look for the little black circle within a circle that is placed in your code where the array is created. Just drag from this circle to all the other UI objects you want to connect to that same collection (not sure if you can mix types). Similarly you can connect all the objects to one Action by dragging from the first black dot created to all the other objects you want to wire up to that action. Also consider EnumerateSequence() to help in working with this Collection. Sweet right?
- Titanium for iOS Development on Windows Platform
- Remove MKMapView Annotations with a certain pinColor?
- What are best practices for validating email addresses in Objective-C for iOS 2.0?
- omniauth for rails and ios authentication
- iOS Geofence CLCircularRegion monitoring. locationManager:didExitRegion does not seem to work as expected
- Upload an image with AFNetworking 2.0
- Converting ex. 2010-09-11T00:00:00+01:00 format to NSDate
- Multithreading and autorelease pool
- Parse push notification in iphone
- Truncate string containing emoji or unicode characters at word or character boundaries
- Xamarin.iOS Target iOS 6 SDK
- Specifying one Dimension of Cells in UICollectionView using Auto Layout
- Get Serial Number of USB HDD (Mac OS)
- NSFileManager – Check file size?
- Error : The service is invalid