如何使用Xcode 5可视化调试器快速查看自定义对象? [英] How can I Quick Look custom objects with Xcode 5 visual debugger?
问题描述
Xcode 5有一个很棒的新功能,您可以将鼠标悬停在变量名称上,并获得UIColor,UIImage甚至UIBezierPath的直观表示。
Xcode 5 has a great new feature where you can hover over a variable name and get a visual representation of a UIColor, UIImage, or even UIBezierPath.
我依稀记得WWDC上的一条评论,开发人员可以遵循某些协议或覆盖任何NSObject子类的某些方法,以便参与这个新的调试功能。我很乐意将它添加到我的一些模型对象中以帮助我调试。任何人都知道这是否真实,或者即使他们在未来的版本中暗示它?
I vaguely remember a comment at WWDC where developers could either conform to some protocol or override some methods on any NSObject subclass in order to participate in this new debugging feature. I would love to add this to a bunch of my model objects to help me debug. Anyone know whether this is a real thing yet, or even if they hinted at it in a future release?
不幸的是,Apple将此功能称为快速查看,由于他们有另一项名为快速查看的技术,我的搜索结果非常嘈杂,我找不到任何有用的东西。
Unfortunately, Apple refers to this feature as "Quick Look" and since they have another technology called "Quick Look" my search results are very noisy and I can't find anything helpful.
推荐答案
这是Xcode 5.1中的一个新功能,可以找到它上面的文档此处。简而言之,您覆盖 - (id)debugQuickLookObject
并返回已支持快速查看的操作系统类型,例如UIImage或NSAttributedString(文档):
This is a new feature in Xcode 5.1, and the documentation on it can be found here. In a nutshell, you override -(id)debugQuickLookObject
and return an OS type that already supports Quick Look, e.g. UIImage or NSAttributedString (full list of types in documentation):
- (id)debugQuickLookObject
{
UIImage *image = [...];
// Drawing code here
return image;
}
对于Swift :
写作时有几个选项,没有理想选择:
There are a few options as of writing, none ideal:
- 符合CustomPlaygroundQuickLookable,但仅限于适用于Playgrounds(需要Xcode 7 / Swift 2)。
- 使用与Objective C相同的方法。这需要将您的类标记为@objc(或继承Objective-C类) )因为调用者依赖于选择器。
- 符合Reflectable,但这需要你提供一个完整的自定义MirrorType以及一堆其他属性以及QuickLookObject(甚至看起来都没有)从Xcode 7开始工作?)
这篇关于如何使用Xcode 5可视化调试器快速查看自定义对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!