I am very new to iPhone development. I often encounter IBAction
, IBOutlet
and so on when reading Objective-C and Swift code. What does IB
stand for?
An IBAction is for hooking a method (action) up to a view when designing your XIB. An IBOutlet lets you reference the view from your controller code. An IBAction lets the view call a method in your controller code when the user interacts with the view.
An IB Outlet (short for Interface Builder outlet) is a graphical component that your code links to. An IB action is the reverse: It is a method in your code that a graphical component links to. It is through these connections that your graphical components are able to do something in response to user input.
@IBAction is similar to @IBOutlet , but goes the other way: @IBOutlet is a way of connecting code to storyboard layouts, and @IBAction is a way of making storyboard layouts trigger code. This method takes one parameter, called sender . It's of type UIButton because we know that's what will be calling the method.
Interface Builder is a software development application for Apple's macOS operating system. It is part of Xcode (formerly Project Builder), the Apple Developer developer's toolset. Interface Builder allows Cocoa and Carbon developers to create interfaces for applications using a graphical user interface.
"Interface Builder".
Before Xcode 4, the interface files (XIBs and NIBs) were edited in a separate program called Interface Builder, hence the prefix.
IBAction
is defined to void
, and IBOutlet
to nothing. They are just clues to Interface Builder when parsing files to make them available for connections.
Just to add the reference, inside AppKit/NSNibDeclarations.h you'll find these:
#ifndef IBOutlet #define IBOutlet #endif #ifndef IBAction #define IBAction void #endif
So, actually, code like this:
@interface ... { IBOutlet NSTextField *label; } - (IBAction)buttonPressed:(id)sender; @end
Will be transformed into:
@interface ... { NSTextField *label; } - (void)buttonPressed:(id)sender; @end
By the preprocessor, even before the compiler sees it. Those keywords were acting just as clues to Interface Builder.
IB stands for interface builder, as you connect objects via the interface builder .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With