加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – Xcode控制台调试输出

发布时间:2020-12-14 17:35:52 所属栏目:百科 来源:网络整理
导读:我从firebase下载数据并将数据显示到tableView上.但是,我发现我的tableView中偶尔会出现重复的内容.我最初认为我不小心在PostService.ps.posts数组中插入了相同的内容.但是,在我重新加载tableView之前设置了一个断点之后,我在控制台中键入了以下命令,输出很
我从firebase下载数据并将数据显示到tableView上.但是,我发现我的tableView中偶尔会出现重复的内容.我最初认为我不小心在PostService.ps.posts数组中插入了相同的内容.但是,在我重新加载tableView之前设置了一个断点之后,我在控制台中键入了以下命令,输出很奇怪.

print PostService.ps.posts

如下面的输出所示,item [4]和item [6]有{…},我不知道它们代表什么(这是我第一次使用console命令进行调试).在我的tableView中.我看到的数据按以下顺序显示[1],[2],[3],[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"
  }

我的所有表数据都是根据PostService.ps.posts中的数据配置的,这些数据的类型为[Post]
在我的viewForHeaderInSection(我在我的应用程序中使用此而不是cellForRowAtIndexPath)中,我有以下代码来配置表

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()
    }

解决方法

最后,我开始知道为什么有些元素将描述显示为{…}.这是由于重复的参考对象打印.在控制台实际对象中让我们看到内容,但重复对象只显示{…}.在您的情况下,您有[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)

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读