IBOutlet 断开连接时如何获取编译器警告

发布于 2024-08-25 09:09:35 字数 205 浏览 2 评论 0原文

如果我的某个对象的 IBOutlet 未连接到 NIB 中的任何内容,我如何才能让 Xcode 发出警告?

我可以通过在 awakeFromNibviewDidLoad 中添加 assert(ofEveryOutlet); 来检查插座在运行时是否已连接。但它不像让编译器为我做检查那么有用或可靠。

How can I have Xcode warn me if an IBOutlet of one of my objects is not hooked up to anything in a NIB?

I can check that outlets are connected at runtime by adding assert(ofEveryOutlet); in awakeFromNib or viewDidLoad. But it's not as useful, or reliable, as having the compiler do the checking for me.

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

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

发布评论

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

评论(2

沫离伤花 2024-09-01 09:09:36

(编译的)NIB 文件是在运行时加载和连接的,所以我认为编译器没有办法检查这一点。我认为你最好的选择是你已经建议的断言......

The (compiled) NIB files are loaded and connected at runtime, so I don't think there is a way for the compiler to check this. I think your best bet is the asserts you've already suggested...

抚笙 2024-09-01 09:09:35

为什么不创建一个单元测试目标来检查您的 IB 绑定并使您的应用程序依赖它。这样每次构建时都会对其进行检查。请参阅http://blog.carbon Five.com/2010/03/testing /testing-view-controllers 有关此方法的示例

Why not create a Unit Test target that checks your IB bindings and make your application depend on it. That way it will get checked each time you build. See http://blog.carbonfive.com/2010/03/testing/testing-view-controllers for an example of this approach

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