|
Suspect that the array "yValues" not being passed to View closure? What am I doing wrong? |
|
Try this
|
|
Thanks @NigelGee. Definitely should have included the Guard statement. But that is not the origin of the error. When I set a breakpoint (debugging) after the last line of code in the .onChange closure, I can see that yValues has the correct number of elements with the correct values. For whatever reason, yValues is not updating in Some View. I'm struggling with Declarative coding as my background has been Imperative code. |
|
You initialize
But in the
You need to account for an empty array in your code or make sure the array is never empty. |
|
Yes, yValues is empty when I define the array. But in the .onChange closure, the array yValues is dimensioned and filled with Doubles. Do I need to first initialize yValues with enough elements (i.e., some number greater than npts) and fill with zeros? Or is it inappropriate to display yValues in Some View? |
|
But
You need to account for an empty array in your code or make sure the array is never empty.
I'm not sure what exactly its purpose is there, so I can't really answer that. (BTW, The name of the |
|
|
|
You could put this around
Now will not be called until the |
|
@NigelGee- As you suggested, wrapping
in a conditional was part of the solution. I also had to re-arrange some of the code to update ContentView AFTER filling the yValues array. I do appreciate the assistance from both you and @roosterboy. As an aside and to give some perspective on my programming experience, I was programming in Fotran for many years. I guess that officially makes me old ;-) |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.