Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

iphone - What does IB mean in IBAction, IBOutlet, etc..?

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?

question from:https://stackoverflow.com/questions/8592056/what-does-ib-mean-in-ibaction-iboutlet-etc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

"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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...