1

I'm currently working on an application in Xcode 8/Swift 3 which runs through APIs. Essentially, I'm parsing information using SwiftyJSON from my MySQL database which keeps the content current and easily updated.

To keep it so the content is also available offline, I'd like to introduce a facility where the data is downloaded and stored on the phone so it is available in "offline mode".

I know it's a completely open question but can anyone point me in the correct direction of how I could make this JSON information available offline? I've tried searching the net with no success.

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
Super_Simon
  • 1,250
  • 8
  • 25
  • for this you can use sqlite / coredata and create table with all attribute and then you should check few thing : 1. schema creation 2. insertion 3.handling old data 4. change schema as per service changed ( most of the time it happens so keep it option open) 5. create model class for attribute initialization . I know it will take time but thats the way you have complete control over your app as compared to using any third party for offline data . i did and working fine in my E-commerce application – Shobhakar Tiwari Jan 24 '17 at 07:53

3 Answers3

1

I know it's not Swift, but the absolute master of this has recently open sauced his master piece: Dash for iOS.

Reviewing what he's done to get rapid scrolling and searches might give some deep insight into how to best do this as done by someone with (arguably) more experience in this area than anyone other than Apple:

https://github.com/Kapeli/Dash-iOS

Confused
  • 6,048
  • 6
  • 34
  • 75
0

I will prefer here 2 option either I will go with 1.SQLite DB or 2. NSURLCache

For SQLite DB you can use FMDB wrapper-https://github.com/ccgus/fmdb

For NSURLCache check this link Best way to Cache JSON from API in SWIFT?

If you just want to save json then go with NSURLCache for offline mode.

Community
  • 1
  • 1
Anil solanki
  • 962
  • 4
  • 20
  • There are Swift alternatives to FMDB (which feels odd in Swift): http://github.com/groue/GRDB.swift (application toolkit) or http://github.com/stephencelis/SQLite.swift (library) – Gwendal Roué Jan 24 '17 at 08:45
0

Achieving offline for iOS is having two best paths they are CoreData and SQLITE. As per the definition of CoreData suggests it is a Model layer of the project. It comes with less efforts on developer side. Bit contrast SQLITE having the same way but little efforts on it.

In my project we are using the CoreData for offline maintenance. Really we have few concerns on the Relational data fetching, Although there is a Predicates representing CoreData for the same still it is limited to some part. These type of situations SQLITE is really a life saver. We can easily fetch the records with simple JOIN commands.

Conclusion:
If you have more complex data relations it's really better to go with the SQLITE, Apart from CoreData is best choice.

Vishnuvardhan
  • 5,081
  • 1
  • 17
  • 33