[swift-users] Customizing my custom type's appearance in the debugger

Tim Vermeulen tvermeulen at me.com
Mon Jul 11 15:48:54 CDT 2016


Hi Enrico,
Thanks for your reply. This means, however, that I can’t easily distribute my code along with this synthetic child provider in a package or a library, correct?

> On 29 Jun 2016, at 19:16, Enrico Granata <egranata at apple.com> wrote:
> 
> Tim,
> the Xcode variables view is controlled by a different mechanism than the playgrounds/po - there is a reference for that mechanism at http://lldb.llvm.org/varformats.html <http://lldb.llvm.org/varformats.html>
> The gist of it is that you're going to want to make a synthetic child provider that returns no child elements for your object - that will be what the variables view picks up
> 
>> On Jun 26, 2016, at 9:41 PM, Dmitri Gribenko <gribozavr at gmail.com <mailto:gribozavr at gmail.com>> wrote:
>> 
>> On Sun, Jun 26, 2016 at 5:03 PM, Tim Vermeulen <tvermeulen at me.com <mailto:tvermeulen at me.com>> wrote:
>>> I already did that, sorry for not providing any code. Take this as an
>>> example:
>>> 
>>> public struct Wrapper<Element> {
>>> 
>>>    private var elements: [Element]
>>> 
>>>    public init<S: Sequence where S.Iterator.Element == Element>(_ sequence:
>>> S) {
>>>        elements = [Element](sequence)
>>>    }
>>> 
>>> }
>>> 
>>> extension Wrapper: Collection {
>>> 
>>>    public var startIndex: Int { return elements.startIndex }
>>>    public var endIndex: Int { return elements.endIndex }
>>> 
>>>    public func index(after index: Int) -> Int {
>>>        return index + 1
>>>    }
>>> 
>>>    public subscript(position: Int) -> Element {
>>>        return elements[position]
>>>    }
>>> 
>>> }
>>> 
>>> extension Wrapper: CustomReflectable {
>>> 
>>>    public var customMirror: Mirror {
>>>        return Mirror(self, unlabeledChildren: self, displayStyle:
>>> .collection)
>>>    }
>>> 
>>> }
>>> 
>>> If I debug an instance of this Wrapper type, then Xcode’s Variables View
>>> will show
>>> 
>>> ▿ wrapper
>>>  ▿ elements = x values
>>>    [0] = 0
>>>    [1] = …
>> 
>> I see.  I'm not sure there's a way to hide anything from Xcode's variables view.
>> 
>> +Enrico.
>> 
>> Dmitri
>> 
>> -- 
>> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
>> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com <mailto:gribozavr at gmail.com>>*/
> 
> 
> Thanks,
> - Enrico
> 📩 egranata@.com ☎️ 27683
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160711/ab27f9b9/attachment.html>


More information about the swift-users mailing list