[NSBundle loadNibNamed:owner:] 在 Xcode 3.1 中如何工作?
我正在一台较旧的 Mac 上进行开发。我无法访问运行 Xcode 3.1 的较新 Mac,但我想确保我的源代码可以在它们上运行。到目前为止,这非常简单,我所要做的就是忽略名称旁边带有“已弃用”的任何内容,但是从 NIB 到 XIB 的更改让我有点困惑。我读过的内容似乎暗示 XIB 在发布构建期间被编译为 NIB,但在调试构建期间可能不会。
这在 Xcode 3.1 中会做什么?
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
[NSBundle loadNibNamed:@"MainMenu" owner: NSApp];
[[NSApp mainMenu] removeItem: [[NSApp mainMenu]itemWithTitle: @"File"]];
[pool release];
[NSApp run];
return NSApplicationMain(argc, (const char **) argv);
}
由于 MainMenu.nib 不存在而导致调试失败?或者每次应用程序编译时 XIB 都会变成 NIB,期间,我不必担心这些?
I'm developing on an older Mac. I don't have access to newer Macs running Xcode 3.1, but I want to make sure my sourcecode will work on them. It's been pretty easy so far, all I have to do is ignore anything with "deprecated" next to its name, but the change from NIBs to XIBs has me kind of tripped up. The things I've read seemingly imply that XIBs get compiled into NIBs during a Release build, but maybe they don't during a Debug build.
What would this do in Xcode 3.1?
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
[NSBundle loadNibNamed:@"MainMenu" owner: NSApp];
[[NSApp mainMenu] removeItem: [[NSApp mainMenu]itemWithTitle: @"File"]];
[pool release];
[NSApp run];
return NSApplicationMain(argc, (const char **) argv);
}
Fail in Debug because MainMenu.nib doesn't exist? Or are XIBs turned into NIBs every time an application compiles, period, and I don't have to worry about any of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XIB 始终编译为 NIB 以供运行时使用。 XIB只是一种基于XML的存储格式。编译 XIB 生成的 NIB 不包含编辑 NIB 文件所需的信息:XIB 编译为只读 NIB。这根本不会影响您的应用程序如何使用它们:就其而言,NIB 就是 NIB 就是 NIB。
XIBs are always compiled into NIBs for use at runtime. XIB is just an XML-based storage format. The NIBs produced by compiling the XIBs do not contain the information needed to edit the NIB file: a XIB compiles to a read-only NIB. This does not affect how your application uses them at all: as far as it's concerned, a NIB is a NIB is a NIB.