I am working on creating a dynamic list using SwiftUI. Does the SwiftUI List
container reuse the cells similar to UITableView
?
Asked
Active
Viewed 8,600 times
19

Gene Z. Ragan
- 2,643
- 2
- 31
- 41

Let's_Create
- 2,963
- 3
- 14
- 33
-
1Why do you ask? I think `SwiftUI` promises to be performant; whether it reuses views in this specific way is an implementation detail. – beyowulf Jun 18 '19 at 19:06
-
3Check the memory graph - it does – Matteo Pacini Jun 18 '19 at 19:23
-
1Sorry to chime in, but I just linked to this question because it seems someone else *may* be wondering something close. I was focused on "dynamic" - State (SO interpreted the "at sign" as a user!), array updates, etc. - and it actually may be the question is more concerned with "reusable". I say (at least for now) leave it up. @Matteo_Pacini has been giving quite a few **great** answers about SwiftUI and Combine.. Maybe he could give another one? I'd surely upvote it. – Jun 18 '19 at 20:38
-
1Check these two answers for more information around this topic: https://stackoverflow.com/a/56652113/5623035 - https://stackoverflow.com/questions/56654877 – Mojtaba Hosseini Jun 18 '19 at 21:34
1 Answers
31
Yes, List
is reusing its ListCoreCellHost
s exactly like the way UITableView
reuses its UITableViewCell
s.
Reference:
Investigating memory usage with Xcode shows that, when the number of the items is more than List
could present at once, it just shows as much as it can and reuses them when they become occluded from the top or bottom of the list
.
By tracing a single cell memory address, you can see it is reused over and over.
Another exciting tidbit is that ListCoreCellHost
uses a hosting view that may refer to UIKit
internally. (Not known well because it lacks documentation)

Velociround
- 611
- 7
- 18

Mojtaba Hosseini
- 95,414
- 31
- 268
- 278
-
By checking the addresses like you suggest, I find that the hosting views and subviews are not reused, only the cell itself. – rens Nov 30 '22 at 17:29