问题描述
我是iPhone开发的新手。我经常在阅读Objective-C和Swift代码时遇到 IBAction
, IBOutlet
等等。 IB
代表什么?
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?
推荐答案
Interface Builder。
"Interface Builder".
在Xcode 4之前,接口文件(XIB和NIB)是在一个名为Interface Builder的独立程序中编辑的,因此是前缀。
Before Xcode 4, the interface files (XIBs and NIBs) were edited in a separate program called Interface Builder, hence the prefix.
IBAction
定义为 void
, IBOutlet $ c $没什么。解析文件时,它们只是Interface Builder的线索,使它们可用于连接。
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.
只需添加引用,在AppKit / NSNibDeclarations.h中你会发现:
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
将转换为:
@interface ...
{
NSTextField *label;
}
- (void)buttonPressed:(id)sender;
@end
通过预处理器,甚至在编译器看到它之前。这些关键字就像Interface Builder一样。
By the preprocessor, even before the compiler sees it. Those keywords were acting just as clues to Interface Builder.
这篇关于IB在IBAction,IBOutlet等中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!