IBOutlet 断开连接时如何获取编译器警告
如果我的某个对象的 IBOutlet 未连接到 NIB 中的任何内容,我如何才能让 Xcode 发出警告?
我可以通过在 awakeFromNib
或 viewDidLoad
中添加 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(编译的)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...
为什么不创建一个单元测试目标来检查您的 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