I'm developing an iOS app which basically fetches a JSON from a remote location, parses it and instantiates classes for a couple of its elements. For some visualization, this should give you a basic idea of what my json looks like:
{
"match": [
{
"id": 1,
"date": "1960-01-01",
"team 1": 1,
"team 2": 2
},
{
"id": 2,
"date": "1960-01-02",
"team 1": 1,
"team 2": 3
}
],
"team": [
{
"id": 1,
"name": "Team Red"
},
{
"id": 2,
"name": "Team Green"
},
{
"id": 3,
"name": "Team Yellow"
}
]
}
This JSON can get quite heavy, once it's completely filled. For my current demo-system I'm talking of 40k lines and ~2 MB file size, but it could easily get way beyond that with my live data. Obviously I'm not loading everything at once, but instead loading the bare basics, that include a couple of required IDs, so I can then make API requests to fetch just the IDs I need for whatever I want to do.
In Swift I've implemented each of the JSONs arrays for further processing:
class Match
- id
- date
- teams
class Team
- id
- name
To save traffic and not have each user to reload everything every time they start the app I want to cache the results, more specifically save them somewhere. But here is where it gets tricky, and where my question lies:
Should I rather create a CoreData representation of each element in order to save them via Core Data and query through them, or could I just save the resulting JSON to the file system, load it once the app starts and re-parse it at that point?
The main advantage of Core Data is from my understanding that I can actually query through my entries and link them, so I could more easily ask "What's the name of the teams from match #1?". Are there any other advantages for me to use Core Data, and which (dis)advantages could you see in writing the JSON file to the disk?