Skip to content

SvenAndreSvensson/SOT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

SwiftUI MVVM iOS 15.0 RC Xcode 13.0 (13A233)

Staus Solution not found
Date 20 september 2021

I have come across some challenges with SwiftUI I can not get past. I am struggling with nested ForEach two-way bindings

  1. Error Index out of range
  2. ? Loses current position when a change is made

BruceLee.MP4

1 Error Index out of range

This error occurs in the second level as I choose to call it, that is, when an element is added to an array, which in turn is part of a structure that is an element in another array.

Structural description, hope this is understandable, yes ...

ForEach($parentData.children){$child in 
  ForEach($child.toys){$toy in 
    // Index out out of range -> when a new toy is added to toys
  }
}
To reproduce the error, do the following:
1. Select a parent
2. Edit parent
3. Select a child
4. Add a toy
5. Enter a name and tap Add button




2 ? Loses current position when a change is made

The expected result when editing the toy, is that by pressing the done button you are brought to the presentation of the toy.

The current result is that you are brought all the way back to the parent. This has something to do with the fact that the list of published parents has been changed, so a redraw is called. It is able to show the correct parent, but it is not able to show the correct child / toy that was the reason for the redraw. Is this a SwiftUI feature or is it me implementing it wrong - that's what I'm wondering

To reproduce the situation, do the following:

1. Select a parent
2. Select a child
3. Select a toy
4. Tap Edit button
5. Change toy name
6. Tap Done button



This example has grown a little bigger than necessary as I have tried to solve the challenge in countless ways. Sorry

About

Nested ForEach two-way binding

Topics

Resources

Stars

Watchers

Forks

Languages