目录
目录README.md

DebugReflect

This library helps dumping your data structure in Swift. It supports classes and reference cycle.

Example

Type implementation.

import DebugReflect

class Cat : DebugReflectable {
    init(name: String) {
        self.name = name
    }
    
    var name: String
    var children: [Cat] = []
    var props: [String: String] = [:]
    var bestFriend: Cat?
    var stone: Stone?

    func debugReflect() -> DebugReflectValue {
        return .build { b in
            b.field("name", name)
            b.field("children", children)
            b.field("props", props)
            b.fieldIfPresent("bestFriend", bestFriend)
            b.fieldIfPresent("stone", stone)
        }
    }
}

struct Stone : DebugReflectable {
    func debugReflect() -> DebugReflectValue {
        return .build { b in
        }
    }
}

Using.

        let cat0 = Cat(name: "apple")
        let cat1 = Cat(name: "banana")
        let cat2 = Cat(name: "cherry")
        cat2.bestFriend = cat1
        cat0.children = [
            cat1,
            cat2,
            cat0
        ]
        cat0.props = [
            "blood": "A"
        ]
        cat0.stone = Stone()
        print(cat0.debugDescription)

Output.

Cat@0x8750e850 {
  name => apple
  children => [
    Cat@0x8750f010 {
      name => banana
      children => []
      props => {}
    }
    Cat@0x8750fb20 {
      name => cherry
      children => []
      props => {}
      bestFriend => Cat@0x8750f010 { recursive }
    }
    Cat@0x8750e850 { recursive }
  ]
  props => {
    blood => A
  }
  stone => Stone {}
}
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号