Why animations in this SwiftUI's List stopped working?

  Рет қаралды 3,191

Swift and Tips

Swift and Tips

Күн бұрын

Пікірлер: 4
@danstoian7721
@danstoian7721 Жыл бұрын
1:01 I'm very curious, why is that range's identity not "stable"? I mean, why is not able to see the range has grown?
@swiftandtips
@swiftandtips Жыл бұрын
Great question. Check out this link that explains the issue very well: www.hackingwithswift.com/forums/swiftui/compiler-warning-non-constant-range-argument-must-be-an-integer-literal/14878
@danstoian7721
@danstoian7721 Жыл бұрын
@@swiftandtips Hi! Just for the sake of anyone listening, a small completion to your great video! And I mean it, I love your videos! If one will look into the Apple documentation for the List initializer that takes a Range and content, one will see the range's identity need not be fixed as it's presumed to be a constant range, and thus only read one. What happens here is, when we add a new element, in todos, who's annotated with @State, it will cause the View to re-draw, thus re-creating the List and reading the Range again. While checking the Todo, does not affect the overall list, but only the inner element, as pointed out by the author.
@swiftandtips
@swiftandtips Жыл бұрын
@@danstoian7721 Great explanation. The problem with the list is that we are using index as ID for SwiftUI. Probably 99% of the time you will be ok, but in some conditions where the sorting find two identical elements, there's no additional criteria to consider to keep one element before other and that could produce a potential inconsistency swapping elements at any new render (or in case of animations). TL;DR: The point of this video was to use a dedicated ID (UUID) for cases like this and do not trust only on Int indices.
Why is this sorting algorithm problematic?
2:28
Swift and Tips
Рет қаралды 808
Performance between LazyVStack, VStack and List #SwiftUI
8:09
Swift and Tips
Рет қаралды 10 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
Avoid THIS Animation Glitch When Hiding TabBar in SwiftUI
11:03
Swift and Tips
Рет қаралды 1,1 М.
Adding Animations in SwiftUI | Bootcamp #25
14:01
Swiftful Thinking
Рет қаралды 35 М.
Controlling the animation stack - Animation SwiftUI Tutorial 5/8
6:30
Xcode 16’s New Folder Format Explained! No More Merge Conflicts!
7:32
How to use Transition in SwiftUI | Bootcamp #27
11:27
Swiftful Thinking
Рет қаралды 33 М.
SwiftUI Profile Animation | Matched Geometry Effect
9:48
Sean Allen
Рет қаралды 18 М.
I Made an iOS App in MINUTES with This AI Tool!
13:20
Creator Magic
Рет қаралды 486 М.
How to use animation with value in SwiftUI (iOS 16+) | Bootcamp #67
10:55
Swiftful Thinking
Рет қаралды 12 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН