Diffable Data Source
Introduced in iOS 13
1
2
API Call
2
4
2 Approaches
1
1 ReloadData - Refresh Semua Data
2 + Biasa-nya Aman
API Call
2 - Gak Smooth
4
2 Approaches
1
1 ReloadData - Refresh Semua Data
2 + Biasa-nya Aman
API Call
2 - Gak Smooth
3 InsertRows - Insert Beberapa Row
3
+ Lebih Smooth
4
- Bisa Crash Kalau Index Salah
SnapShot
Records Previous Changes
New SnapShot
Previous SnapShot
1
1 Apply SnapShot
3
Records Previous Changes
New
Previous
1
1
Compare
Animates 3
Records Previous Changes
New
New Previous
Previous
1
1 1
1
Compare Compare
2
2 2
2
3
Animates 3 3
Animates 4
Records Previous Changes
New
Previous
1
1
Compare
3
Animates
4
Animates
Records Previous Changes
New
Previous Previous New
1
1
Compare 1
Compare 1
2 2 Animate
2
Disappear
3
Animates
4
Animates
Records Previous Changes
Previous New
1 1
Compare
2 2
3 3
Nothing Will Happen - Will Not Trigger Refresh At all
How It Works?
Previous New
The Hashable Protocol - Inherit From Equatable
1 1
Compare
Struct <Struct Name> : Hashable
let name: String
2 2
let description: String
3 3 Hashable Will Create Unique Hash Value
- Used In Dictionaries and Sets
Hashable Behind The Scenes
Previous New
1 Hash Value: e123 1 Hash Value: e123
Compare
2 Hash Value: e234 2
Hash Value: e234
3 Hash Value: e345 Will Change 4 Hash Value: e456
Diffable Data Source
Gak perlu worry tentang animasi insert/remove/reload
Cuman pikirin data lama dan data baru
Diffable Data Source
Pros: Gak perlu worry animasi perbedaan data
Cons: Semua data dalam SnapShot harus unique (no duplicates)