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?
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?
- Aligning multiple sized text vertical center instead of baseline with Core Text in iOS
- How to add the UISegmentedControl in UINavigationBar?
- How can I use a PKCS8 RSA DER Private Key in iOS?
- Getting country calling prefix
- Payment Gateway integration in iPhone
- Adding Older iOS SDKs to Xcode 4.1 in Lion
- Image not store in sqlite
- JSONSerialization with Swift 3
- How can I use commercial at sign in Objective-C macro?
- Exhaustive condition of switch case in Swift
- Facebook Graph API GET request – Should contain “fields” parameter (Swift, Facebook SDK v4.5.1)
- Cancel GCD async task when navigating back
- Xcode 7.3 Syntax Highlighting and Code Completion issues with Swift
- Can't submit app to AppStore. “Your application bundle's signature contains code signing entitlements that are not supported on iOS”
- can't make tab bar hidden when using container views