Nested hierarchy view (for comment system) : <p>I'd like to implement a commenting system where users can reply to others who've left comments. I'd like to display these comments in a nested hierarchy view, similar to what the reddit app "Apollo" does below:</p>

<p><a href="https://i.imgur.com/JiLLsjs.mp4" rel="nofollow noreferrer">https://i.imgur.com/JiLLsjs.mp4</a></p>

<p>As you can see, the comments are sorted in a nested format.</p>

<p>Here is what my API response looks like:</p>

<pre><code>{
    "success": true,
    "data": {
        "comments": {
            "data": [
                {
                    "id": 1,
                    "parent_id": 0,
                    "depth": 0,
                    "message": "1",
                    "children_count": 2,
                    "children": [
                        {
                            "id": 2,
                            "parent_id": 1,
                            "depth": 1,
                            "message": "2",
                            "children_count": 1,
                            "children": [
                                {
                                    "id": 3,
                                    "parent_id": 2,
                                    "depth": 2,
                                    "message": "3",
                                    "children_count": 0,
                                    "children": []
                                }
                            ]
                        },
                        {
                            "id": 4,
                            "parent_id": 1,
                            "depth": 1,
                            "message": "2",
                            "children_count": 0,
                            "children": []
                        }
                    ]
                },
                {
                    "id": 5,
                    "parent_id": 0,
                    "depth": 0,
                    "message": "1",
                    "children_count": 0,
                    "children": []
                }
            ]
        }
    }
}
</code></pre>

<p>As you can see, each <code>comment</code> object has a <code>parent_id</code> (the parent comment ID), a <code>depth</code> (basically the "level" of the comment in the hierarchy), a <code>children_count</code> (the number of direct children), and <code>children</code> (the children comments themselves).</p>

<p>So with that, my questions are:</p>

<ol>
<li>How would this best be implemented? As a table view, collection view, or something else? I assume I would create a xib for the comment view itself?</li>
<li>What is the best way to approach actually implementing this? How should I loop through the API response?</li>
<li>How do I add a margin/padding to the left side to make a comment look nested?</li>
<li>How do I make the cells expandable?</li>
<li>What should I know about in terms of memory management?</li>
</ol>

<p>Thanks.</p>
