ios - Xcode 中有 var_dump 吗?

标签 ios xcode

我来自 php 背景...所以我想知道 Xcode 是否有 var_dump 这样的东西,我知道 NSLog 但我想要它表现得像 var_dump

有这个功能吗?

最佳答案

在 swift 中,您可以使用 dump(var),它使用镜像进行内省(introspection)并且对类很有用。

例如:

let pet = Pet(name:"Max", age: 4)
let adam = Person(name:"Adam", age: 30, pet:pet)

print("\(pet)")
print("\(adam)")
print("======")
dump(pet)
dump(adam)

输出将是:

Pet
Person
======
▿ Pet #0
  - name: "Max"
  - age: 4
▿ Person #0
  - name: "Adam"
  - age: 30
  ▿ pet: Optional(Pet)
    ▿ some: Pet #1
      - name: "Max"
      - age: 4

关于ios - Xcode 中有 var_dump 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19914895/

相关文章:

ios - 多个目标上的 Facebook SDK iOS

ios - RxSwift 中 Disposables.create() 的目的

objective-c - 在 RestKit 中序列化嵌套图像(Rails 后端)

ios - "AssetsPackManifest.plist"无法删除

ios - 设置表头 View 的高度时出现奇怪的行为

xcode - 使用Xcode 8.1提交应用商店

javascript - jQuery Mobile 按钮在按下时不会立即更改为 'pressed' 状态

ios - AVPlayer 在后台停止

swift - 为不同的设备创建不同的场景

ios - 使用 linphone ios sdk 的冲突类型错误