IBOutletCollection set ordering in Interface Builder

EDIT: Several commenters have claimed that more recent versions of Xcode return IBOutletCollections in the order the connections are made. Others have claimed that this approach didn’t work for them in storyboards. I haven’t tested this myself, but if you’re willing to rely on undocumented behavior, then you may find that the explicit sorting I’ve … Read more

How to loop through view outlets in a UIViewController with Swift?

This is what Outlet Collections are for. Drag all your textfields in the same Outlet Collection in InterfaceBuilder and create an @IBOutlet to that collection in your class file: To create the outlet collection in InterfaceBuilder, ctrl-drag from the first UITextField to your class file in the assistant editor. Then choose Outlet Collection: ctrl-drag the … Read more

Could not insert new outlet connection: Could not find any information for the class named

Here are some things that can fix this (in increasing order of difficulty): Clean the project (Product > Clean) Manually paste in @IBOutlet weak var viewName: UIView! // or @IBAction func viewTapped(_ sender: Any) { } and control drag to it. (Change type as needed.) Also see this. Completely close Xcode and restart your project. … Read more

IBOutlet and IBAction in Swift

When you attach a button to the viewController and create an action (IBAction) using ctrl-drag, you create a method that looks likes this in Swift (if it doesn’t have arguments): @IBAction func buttonAction() {} In Objective-C the same thing will look like this: – (IBAction)buttonAction {} So that means that @IBAction func OK(sender: UIButton){} is … Read more

IBOutlet is nil, but it is connected in storyboard, Swift

Typically this happens because your view controller hasn’t loaded its view hierarchy yet. A view controller only loads its view hierarchy when something sends it the view message. The system does this when it is time to actually put the view hierarchy on the screen, which happens after things like prepareForSegue:sender: and viewWillAppear: have returned. … Read more