Parijat Kalia
Parijat Kalia

Reputation: 5085

Curiosities noticed while learning Objective-C and Xcode in general

While specifying an instance variable that provides a connection between the view controller and the View, we use the IBOutlet keyword prior to the View object type. This helps indicate that it is an instance variable connecting to the View.

However, is there a scenario where I would not require the IBOutlet keyword preceding my view Object type? For example: can we have a scenario where a:

UIButton *display ;

has some kind of use vs

IBOutlet UIButton *display ;

This question stemmed out of curiosity.

Another question that I have probably has to do with understanding the nuances of interfaces and C in general.

In the view controller or any controller as such, we tend to "import" the header files and not the implementation files. I am at odds with this concept and again it is just a curiosity?

Upvotes: 0

Views: 89

Answers (3)

Callum Jones
Callum Jones

Reputation: 595

IBOutlet and IBAction helped Interface Builder detect what outlet and actions you wish to connect to your UI controls, at compile time these IBOutlet and IBAction are ignored and have no use.

I believe you don't need these keywords anymore in Xcode 4.0+.

You can have a scenario where you don't need IBOutlet or IBAction, when you are building UI controls programmatically (in code).

Upvotes: 0

Flyingdiver
Flyingdiver

Reputation: 2142

To the compiler, IBOUTLET is a null operator. It means nothing. It's only purpose is to tell Interface Builder that you intend to connect it to an interface object.

Header files define the interface, and that's all the other class implementations need.

Joe

Upvotes: 2

jtbandes
jtbandes

Reputation: 118691

The "IBOutlet" keyword doesn't change anything about your program, it just allows Interface Builder to recognize what connections are available. If you don't need to connect something in your interface (for example, if you just want an instance variable for private storage, or if you want to use an @property), then you don't have to use IBOutlet.

We import header files just so the compiler knows what classes and methods are available when using them from other places in the program. An implementation file doesn't need to be imported; it only needs to be compiled into the program and the things it contains will be available.

Upvotes: 2

Related Questions