你应该如何在 XCode 中以交互方式调试 Swift 类? [英] How are you supposed to interactively debug Swift classes in XCode?

查看:22
本文介绍了你应该如何在 XCode 中以交互方式调试 Swift 类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Obj-C,在 XCode 中以交互方式查看值从来没有任何问题,但是使用 Swift 应该如何完成.这是一个例子,我想看看一个视图控制器的帧的值是什么,这里是代码和当前执行的行:

这是完全展开的变量窗口显示的内容:

这对于查看继承值完全没用.

好的,让我们试试 po.

这是开玩笑吗?为什么 po 说 vc 未解析,而显然它必须在断点处的范围内.

那么应该如何在 XCode 中以交互方式查看 Swift 中的变量?

解决方案

参考你提到的内容:

<块引用>

我想看看视图控制器框架的值是什么

UIViewController 没有有一个框架,你可能想看看它的

  • 您可以添加 - 作为表达式 - 您想要跟踪的任何对象,即查看其实际值.例如,我添加了 self.view.frame 并且输出是(iphone 6 模拟器):

对于您的具体情况,添加 vc.view.frame - 作为表达式 - 应显示您要查找的内容.

希望这有帮助.

With Obj-C there's never any problem viewing values interactively within XCode, with Swift however how is this supposed to be done. Here's an example, I want to see what the values of a view controller's frame is, here the code and the current line of execution:

And here's what the variables window show fully expanded:

That is totally useless for viewing inherited values.

Ok lets try po.

Is this a joke? Why is po saying vc is unresolved when clearly it must be in scope at the breakpoint.

So how is one supposed to view variables interactively in Swift in XCode?

解决方案

Referring to what are you mentioning:

I want to see what the values of a view controller's frame is

UIViewController does not has a frame, you probably meant to see its view frame.

However, the easiest way -for me- to see such values, is to add an expression, as follows:

After reaching the desired breakpoint:

  • In the debug area - variables view, right clicking and choosing "Add Expression..." option should display the following pop-up view:

  • You can add -as an expression- whatever object you want to trace, i.e to see its actual value. For instance, I added self.view.frame and the output was (iphone 6 simulator):

For your specific case, adding vc.view.frame -as an expression- should display what are you looking for.

Hope this helped.

这篇关于你应该如何在 XCode 中以交互方式调试 Swift 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆