Sorry for the late reply, I didn't get a notification for this update unfortunately... Where exactly do I have to put this to get the desired effect?
Post
Replies
Boosts
Views
Activity
I created a TEST-API including all the app-code, so you can see everything in detail and can even post and get data from a test-server to see exactly what's going on. Hope this helps... silvioberger.ch/TEST-API.zip
DataService is already an ObservableObject class and has sortedDatapoints as published var within. So everything should be set-up correct, right? I can try to post more of the code tomorrow, as it might help understanding all the processes within the app.
I watched the video. If I didn‘t misunderstand, the way I built everything should conform to the way it‘s meant to be; I have DataService at a pretty high-level in the hierarchy which is an ObservableObject (source of truth), having properties that are Published. On the respective views I reference DataService as a whole as StateObject (only referencing the SOT, not creating a view-local copy of it). Could you confirm my understanding comparing my code, or do I miss something?
Depot is a struct but the data is changed in DataService which is indeed a class. According to you, it won‘t be considered as a change then, right? Where should I put the published var? In the DataService class (the var sortedDatapoints which is used for the list is already a published one in the DataService class though)?
Also when you have a closer look to the line print(DATA.sortedDatapoints[0].amount) in DepotstandAdd.swift the amount I get there is actually the freshly inserted value, so the response from the server seems to be alright.
I think I already do the first approach (in the readDepot function of DataService I reassign the sortedDatapoints, which later build the list in DepotDetails), but maybe I am missing something or misunderstand the mechanic behind it...
Also thanks for the URL, I will watch the video later on (and hopefully get a better understanding on this complex topic).
Thanks for your very fast reply.
I use the DataService as @StateObject which gets/puts data via REST and also sets observed objects like sortedDatapoints and so on.
So in my thinking the data should be ready and synced and the view should be refreshed due to the meanwhile reassigned variables inside the @StateObject of DataService, but it doesn't seem to be the case...
I don't really get all these different data dependencies, as this is my first project, so I use it as I understand.
@OOPer sorry, my fault - I cleaned all code a little bit up, to be able to provide more info and now it works! :-) So it was a problem on my side somewhere... Thank you very much for your help!
@OOPer this it the error-message printed by ModelDataDepot using the same JSON-data as shown in the question when I try to run the build. What additional info would you need that I could give you? Thanks for your help!
Hi @OOPer, thanks for your answer and explanation. I've tried it and it seems to be better, but now I get a similar error on the amount member: JSON-Error: typeMismatch(Swift.Double, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "datapoints", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "amount", intValue: nil)], debugDescription: "Expected to decode Double but found a string/data instead.", underlyingError: nil))
Hi @seamount
Thanks a lot! It worked for me as well. :-)