Ios Xcode控制台调试输出

Ios Xcode控制台调试输出,ios,objective-c,xcode,uitableview,Ios,Objective C,Xcode,Uitableview,我正在从firebase下载数据并将数据显示在tableView上。然而,我发现在我的tableView中不时出现重复的内容。我最初认为我无意中在PostService.ps.posts数组中插入了相同的内容。然而,在我重新加载tableView之前放置了一个断点之后,我在控制台中键入了以下命令,结果很奇怪 打印PostService.ps.posts 如下面的输出所示,项[4]和项[6]有{…},我不知道它们代表什么(这是我第一次使用console命令进行调试)。在我看来。我看到数据按以下顺序

我正在从firebase下载数据并将数据显示在tableView上。然而,我发现在我的tableView中不时出现重复的内容。我最初认为我无意中在PostService.ps.posts数组中插入了相同的内容。然而,在我重新加载tableView之前放置了一个断点之后,我在控制台中键入了以下命令,结果很奇怪

打印PostService.ps.posts

如下面的输出所示,项[4]和项[6]有{…},我不知道它们代表什么(这是我第一次使用console命令进行调试)。在我看来。我看到数据按以下顺序显示[1]、[2]、[3]、[5]、[5]、[6]、[7]、[8]、[9](从第0行到第8行)。因此,第3行(起始表单0)获得的数据与第2行相同,第5行获得的数据与第4行相同。奇怪

我不知道为什么会发生这样的事情,我没有地方可以开始,因为它不是每次都会发生。我希望这个控制台输出能帮助我找到正确的方法

  [1] = 0x000000012f4849b0 {
    _postKey = "-KQTh_WDO2IS1rYfLgnU"
    _userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
  }

  [2] = 0x0000000130e61f40 {
    _postKey = "-KQTHnE4IIeBR3tyDM3r"
    _userId = "1isMS98ZmXYrpCmGb4o5voaAqXH2"
    _image = "www.image2.com"
  }

  [3] = 0x0000000130192b40 {
    _postKey = "-KQtN4YG51HOF19FrM8s"
    _userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
    _image = "www.image3.com"
  }

  [4] = 0x0000000130192b40 {...}

  [5] = 0x0000000130269560 {
    _postKey = "-KR2On6u7dRy0GAvE1Gn"
    _userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
    _image = "www.image4.com"
  }

  [6] = 0x0000000130269560 {...}

  [7] = 0x000000013150f4c0 {
    _postKey = "-KQThGLVA-MsviGMsXOS"
    _userId = "1isMS98ZmXYrpCmGb4o5voaAqXH2"
    _image = "www.image5.com"
  }

  [8] = 0x000000012fa88890 {
    _postKey = "-KQt269uHGM99oFKuJRt"
    _userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
    _image = "www.image6.com"
  }

  [9] = 0x000000012f9bcad0 {
    _postKey = "-KQThdCAm-PlCsCnXcBZ"
    _userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
  }
我的所有表格数据都是基于[Post]类型的my PostService.ps.posts中的数据配置的 在我的viewForHeaderInSection(我在我的应用程序中使用它而不是CellForRowatineXpath)中,我有以下代码来配置表

    if let cell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("TableSectionHeader") as? TableSectionHeader {
        let post = PostService.ps.posts[section]
        var image: UIImage?
        if let url = post.imageUrl {
            image = DiscoverVC.imageCache.objectForKey(url) as? UIImage
        }            
        cell.configureCell(post, image: image)
        cell.delegate = self

        return cell

    } else {
        return TableSectionHeader()
    }

好的,我读了你的问题,让我帮助你理解你用来打印
PostService.ps.posts
数组元素的命令

po
命令打印对象的“描述”方法

尝试将
po PostService.ps.posts[section]
写入
viewForHeaderInSection
中,它将打印
post
类型对象

在这里,您可以打印
post
自定义类对象的所有属性,如下所示:- 现在写
po post.imageUrl
po post.postKey
po post.userId


交叉检查所有标题的所有这些输出。检查这些值是否相同或不同。如果这些值不同,则问题将出现在表单元格的出列中,否则如果这些值相同,则问题将出现在服务器逻辑(后端)中。

根据我多年使用Xcode的个人经验,控制台日志不太可靠,特别是在打印收集对象时,试着记录你怀疑的具体项目,看看会发生什么

最终,我知道了为什么一些元素显示为{…}的描述。这是由于重复的参考对象打印造成的。在控制台中,实际对象允许我们查看内容,但重复对象只是显示为{…}。在您的例子中,有[3]和[4]元素,[5]和[6]元素具有相同的引用,因此重复的元素显示{…}。为此,我尝试了一个简单的例子。希望它能澄清这一点

import UIKit

class ViewController: UIViewController {

    class model {
        let first = "first"
        let second = "second"
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        var array = [model]()

        let obj = model()
        let obj1 = model()

        array.append(obj) // original objct
        array.append(obj) // duplicate because classes are referece types
        array.append(obj) // duplicate because classes are referece types
        array.append(obj1) // new Object

        print(array)


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
输出:

(lldb) print array
([SampleDebugApp.ViewController.model]) $R0 = 4 values {
  [0] = 0x00007fed8ac93990 (first = "first", second = "second")
  [1] = 0x00007fed8ac93990 {...}
  [2] = 0x00007fed8ac93990 {...}
  [3] = 0x00007fed8ac939d0 (first = "first", second = "second")
}
(lldb)

注意:它只发生在类对象的数组上。因为类是引用类型。

但内容是different@Mr.UB你是什么意思?尝试indexpath.section而不是section谢谢你找到了!我认为这是一些奇怪的错误,比如指针或内存问题。我不认为Xcode有什么好的理由不打印出来,尽管。。。真奇怪。