SwiftUI, iPhone app with json file

Hi,

I try ti develop an iPhone app for my personal use.

I use swiftUI on xcode. What i want is to do an app with :

  • homepage (name: menu) :
    • List of all my films
    • link to another swiftUI view with each films' informations
  • films informations (name: contentview) :
    • toggle if the film was seen
    • slider (1 to 5) to note the film


I use a json file with :

  • id : Int, each film has a different id
  • nom : String, title of the films
  • idL : String, first letter of the film
  • note : Int, note of the film
  • isShow : Bool, true if the film was seen, false if not


On the homepage i want to display each title with an arrow to go to informations page

I want to separate films' list by section (idL), for the moment i just have the list...


example :

A
All "A..." films
B
All "B..." films
...
I want to link toggle and slider with the json attributes and with UserData to dinamically change these properties to modify when i see new films.

For the moment, when i change toggle value or slider value, it works for each film but when i close the application, it disappear... and it's not link to the json file attributes...




Link of the .json file I use :

https://gist.githubusercontent.com/thomjlg/0782e9e8e27c346af3600bff9923f294/raw/514bf34829d8ce964bd1182430dacc8a6ff2fe66/films2.json


My project on GitHub : https://github.com/thomjlg/Films-APP



Thanks for your help !

Replies

That's good to have a link to the whole project.


But for fast access for those who read, you should also show the code for most relevant parts directly in the post.

hi Thomas (and readers)


i probably have some experience on this project, since you asked yesterday in the HackingWithSwift forums about adding a search bar to this project and i did look through it.


i've posted some code for you to look at this project on github: delawaremathguy/Thomas.


basically, let's address only one thing here that you are asking about in this post:

to get your code to save correctly, you have to update the userData.movies array and then write it out. i don't think you were doing that in your project as i saw it yesterday -- you were updating an individual movie, but not updating its entry in the userData movies array. the code to read and write to your documents directory is working fine -- you just kept writing out the same thing with no changes.


for the code that i have posted above, i've added a few lines here and there to be sure to get this done, as well as to incorporate some code i posted yesterday on HWS (albeit slightly modified) so that the search bar works as well.


as for the other thing, welll that's a different matter. doing one big list is what i have shown in the code; but getting lists to section out (dynamically, as data changes) is a little more tedious in SwiftUI, so i would defer that for now, work on other parts of your project, and hope that SwiftUI 2.0 will make it easier.


hope that helps,

DMG