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

Dmitri Gribenko gribozavr at gmail.com
Sun Jun 26 23:41:59 CDT 2016


On Sun, Jun 26, 2016 at 5:03 PM, Tim Vermeulen <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>*/


More information about the swift-users mailing list