Cocoa 应用程序引导问题

发布于 2024-09-10 12:04:35 字数 1436 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月棠 2024-09-17 12:04:35

XCode 生成的“委托”包含 NSPersistentStoreCoordinator、NSManagedObjectModel 和 NSManagedObjectContext 的实例 - 请详细说明吗?

这是核心数据内容。

委托被声明为“@interfacetests_AppDelegate:NSObject{”。为什么缺少协议?我在网上看到了一些例子。

可能是一个疏忽。 AppKit 并不总是有正式的 NSApplicationDelegate 协议。苹果可能根本就没有更新过这些模板。您可以提交错误

我看到应用程序委托是在 Interface Builder 中实例化的。它在哪里传递到 NSApplication 实例中?

右键单击应用程序对象。您会发现它的 delegate 出口已连接到委托对象。

The "delegate" that gets generated by XCode contains instances of NSPersistentStoreCoordinator, NSManagedObjectModel, and NSManagedObjectContext -- details please?

That's Core Data stuff.

The delegate is declared "@interface tests_AppDelegate : NSObject {" . Why is the protocol missing? I see examples on the net with it there.

Probably an oversight. AppKit didn't always have a formal NSApplicationDelegate protocol. It's possible that Apple simply never updated the templates. You might file a bug.

I see that the application delegate is instantiated inside Interface Builder. Where is it passed into the NSApplication instance?

Right-click on the application object. You'll find that its delegate outlet is connected to the delegate object.

明月夜 2024-09-17 12:04:35
  1. 只有当您将模板用于基于 CoreData 的应用程序时,才会发生这种情况。阅读 核心数据基础知识

  2. 该协议仅在 OS X 10.6 中正式化。在此之前,这是非正式完成的。只要委托实现了参考中提到的选择器,它就会被调用。代表并不严格需要明确采用协议。当然最好还是这样做。请参阅 NSApplicationDelegate 参考。每个条目都有评论

    <块引用>

    适用于 Mac OS X v10.0 及更高版本。
    在 Mac OS X v10.6 之前作为非正式协议的一部分提供。

    该协议

  3. 在界面生成器中,您会看到委托被分配给文件所有者的“委托”出口:右键单击文件所有者,您可以看到这一点。 nib 文件包含在 IB 中创建的冻干对象。当应用程序在初始化过程中读取 MainMenu.nib 时,它会分配 NSApp
    作为文件的所有者。因此,在 nib 文件中实例化并冻结的应用程序委托被分配给 NSApp 的委托。阅读 Nib 文件。。 p>

  1. That only happenes if you use the template for a CoreData-based apps. Read Core Data basics.

  2. The protocol was only formalized in OS X 10.6. It was done informally prior to that. As long as the delegate implements the selector mentioned in the reference, it gets called. It's not strictly necessary for the delegate to explicitly adopt a protocol. Of course it's better to do that. See NSApplicationDelegate reference. Every entry has the comment

    Available in Mac OS X v10.0 and later.
    Available as part of an informal protocol prior to Mac OS X v10.6.

  3. In the Interface Builder you see the delegate is assigned to the "delegate" outlet of the File's Owner: right-click on the File's Owner and you can see that. The nib files contain freeze-dried objects created in the IB. When the app reads MainMenu.nib as part of the initialization process, it assigns NSApp
    as the File's Owner. So the app delegate instantiated and frozen inside the nib file gets assigned to NSApp's delegate. Read Nib Files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文