8

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.

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?

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.

Lightbow
  • 143
  • 1
  • 6

2 Answers2

14

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;
}

For Swift:

There are a few options as of writing, none ideal:

  • Conform to CustomPlaygroundQuickLookable, but that only works in Playgrounds (and requires Xcode 7/Swift 2).
  • Use the same method as for Objective C. This requires your class to be marked @objc (or inherit a Objective-C class) as the caller relies on selectors.
  • Conform to Reflectable, but that requires you to provide a full custom MirrorType with a bunch of other properties along with the QuickLookObject (and doesn't even seem to work as of Xcode 7?)
Patrick Pijnappel
  • 7,317
  • 3
  • 39
  • 39
3

Now that 5.1 has been officially released I've released this new blog post on the matter.

To answer your question: Yes, this is indeed a feature available in the new release of XCode (v5.1) and can be used very easily by subclassing an object and returning whatever it is you want to see while debugging in a -(id)debugQuickLookObject method.

Stavash
  • 14,244
  • 5
  • 52
  • 80
  • 1
    that was quick! Thanks for contributing to the quality of this site :-) – kleopatra Mar 11 '14 at 09:37
  • 1
    How can this be used with C++ classes? – Adi Shavit Mar 13 '14 at 16:05
  • @AdiShavit Maybe wrap cpp classes with Objective-C classes to enables this? – Stavash Mar 13 '14 at 16:27
  • I guess that would work for inspecting specific class instances. – Adi Shavit Mar 13 '14 at 20:12
  • And how this can be done when your source code is compiled to *.a library and you only release headers and library? – lvp Mar 29 '14 at 15:40
  • @lvp why wouldn't this work while debugging? Have you tried this? – Stavash Mar 30 '14 at 09:05
  • Yes of course in two projects. One normal (and it worked) and one with static library (*.a) where `debugQuickLookObject` was implemented in source file compiled into that library. With second project it didn't worked :( – lvp Mar 30 '14 at 09:27
  • Interesting find, I haven't found any documentation for this. Would be interesting to open a thread on the developer forums. – Stavash Mar 30 '14 at 09:58
  • I already got reply from Apple Developer on their forum (https://devforums.apple.com/) `As you noted, debugQuickLookObject is not currently called in libraries like this. We're tracking this enhancement request.` So we need to wait. – lvp Mar 31 '14 at 06:40