Xcode 8/Swift 3: make API information available offline? [duplicate] - ios

This question already has an answer here:
How to make offline database for my app?
(1 answer)
Closed 6 years ago.
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.

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

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.

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.

Related

Developing Quiz App - Data Storage iOS

I am planning to develop a quiz app in iOS and doing it offline. I need to store 100s of questions and options in that app. How to store? How does core data comes in handy here? Is there any other good methods for this problem?
The app is meant to be offline.
You can also use SQLite database for saving Questions and Answers offline for your Quiz app. You can create tables in SQLite and save and fetch data from that using SQLite queries.
I would recommend you to use realm.io. It measures better than core data, its fast and simple to use. On https://realm.io there is lots of documentation.
I find realm much easier to set up and in generally to comprehend. It works nicely with SwiftJSON and hence in my view much easier to connect to backend.
Preloading core data can be quite cumbersome and to me it seems that core data still relies heavily on objective c.
On the other Core Data is made by Apple so it could be more stable solution on longer run (parse.com)

Information about API's, Core data iOS design from the start

Good Morning,
I am in the process of designing an app. It will capture data in the device and will sync with a web server, I have a few months learning Swift to develope iOS apps and I am learning to use core data now with small samples.
I have a book I've been reading and available resources like this one:
https://developer.apple.com/library/watchos/documentation/Cocoa/Conceptual/CoreData/index.html
My question is:
Do I have to start learning how to sync and save data in the device at the same time? or I can learn Core Data first, make the app and then start the process of syncing (using JSON)?
What available resources can I see to learn what I need?
This is new for me, I have a friend who knows Ruby and has knowledge about API, but he does not know how mobile devices works in this matter.
I have searched here, but a lot of question and answers I see covers specific topics.
Your help and time is really appreciated. Thanks!
P.S.
I apologize for the term sync (send and receive data to/from the server) if I a using it wrong, or should I use the term API? For me is a little confusing on how to use the term, since it is use for a few things, like data, but also it's used when talking about a method which all the info you need to go to the API of the method, function or class.
The process you should follow is first learn basic iOS developemeet. Check out the tutorials at raywenderlich and hacking with swift. In the process you will learn a bit about networking(working with APIs) and Data Persistence(Core Data).
Since collection of data precedes storage of data you must learn first about REST APIs, JSON, JSON parsing and related stuff, third party libraries available like Alamofire and SwiftyJSON(these can be installed using cocoapods)
And then jump into data persistence which can be done through sqlite database(FMDB is a wrapper available and is super easy), Core Data, NSUserDefaults, plist, Realm etc.

Apple ResearchKit: how to extract information from ORKResult? First time programmer

I'm working on a simple ResearchKit app that has 20 survey questions, or ORKSteps. How do I get the answers from a participant who submits the survey into a database?
My research has found ORKESerializer and SQLite as potential parts of the solution. I'm missing a big picture view of how these things can be integrated into a working solution.
Starting without knowledge of databases or data transfer from Swift, so any basic information would be very helpful.
How do I extract data from ORKResult using Swift?
Where do I extract the data to? Or, what's the standard type of database for a small survey?
ResearchKit doesn't have any out-of-the-box solution for storing your results. Generally, it's the task of the developer to go through the ORKResult hierarchy and either persist the processed results for later access or send them to a remote server.
You have several options here:
Use NSCoding to store the vanilla ORKTaskResult (with their ORKResult children). This way you can recreate the whole ORKTaskResult hierarchy at later time to inspect or process it.
Use ORKESerializer (as you guessed) to serialize ORKResults into the JSON format. ORKESerializer is currently included as part of ORKTest's unit tests, and it's not documented very well. It's possible that it will be moved to ResearchKit proper in the future, but it's completely usable right now. The JSON format is particularly useful if you want to send your results to any remote server of your own.
You can manually iterate through ORKResults and convert them into objects that are suitable for storing, or into database records. As you said, you could persist them using SQLite; or other database of your choice; or Core Data.
To sum up, there's no recommended or standard method for persisting results, it depends on your needs.
You can also have a look at the official open sourced RK apps. I think they make use of the AppCore library (which sits on top of the ResearchKit) to store the task results (and also use the Sage Bridge to send the results to Sage's servers). But that may be overboard if your needs are simpler.
I suggest that you run the sample ORKCatalog app and then inspect the ORKTaskResult hierarchy (you can do that within the app itself). You'll get an idea of how the result hierarchy looks.
I do not have experience with the Research Kit but as a database you could use sqlite. stephencelis has made a great wrapper for swift which you can use.

SQLite or coredata or other [duplicate]

This question already has answers here:
Use CoreData or SQLite on iPhone? [closed]
(3 answers)
Closed 9 years ago.
This is for an iphone app. What's the best route that I should take? I have data and I would like to have it in my app and access it throughout the app in different ways search, title, state, etc.
I don't want the user to be able to modify it or delete it.
Should I use core data or SQLite or is there a better way?
Thank you
I personally would recommend using CoreData for its ease of use. CoreData, in fact, act as an abstraction layer over SQLite so, you don't need to actually write any SQL lines.
Take a look at the CoreData documentation from Apple so you can understand exactly what it is. Or, maybe, you can jump to their Tutorial for a "hands-on" explaining:
Core Data Tutorial for iOS
Also, I personally like to use tutorials from the Ray Wenderlich sites, like this one:
Core Data on iOS 5 Tutorial: Getting Started
(by the time of writing this, the Ray Wenderlich's site is under maintenance.. but check it out later.. it is pretty good!)

SQLite or CoreData [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Use CoreData or SQLite on iPhone?
I would like to build an App which enables you too find stores (for example stores with your favourite shoe brand) even when you're not connected with WiFi or 3G.
For now the App should have a couple of possibilities:
User selects his favourite brand and gets a list of nearby stores. After that the user must be able to select a store to get the address, contact information and maybe a map;
User selects a certain city, gets a list of the available brands, selects one and gets a list of stores in that city selling the selected brand.
Since I'm new to making this kind of Apps, I have started doing my homework. I know I have to use a database to store all the data and found out there are a lot of ways to do so. One of them, creating a MySQL Database, wouldn't be an option since it can't be used offline. If I'm right two other methods are SQLite or CoreData.
Problem is, I'm getting kinda lost in all the available information which makes it hard for me to start. Are both methods possible for this App and which one is the easiest for this job?
I was hoping someone could point me in the right direction and maybe give me an usefull link or tutorial to continue with my App.
Thanks in advance! :)
Only use SQLite if you already know it, or you know that your use case is one of the rare few that has proven difficult for Core Data.
Thus, I would think your decision is simple. Use Core Data. It's extremely simple, unless you start updating data from multiple threads/contexts at the same time, then it gets pretty hairy relatively quickly.
There are tons of tutorials available online for Core Data, and ou always have Apple's documentation and sample code on their developer web site.
If you've never used MySQL or SQLite, just use CoreData. But if you have used MySQL or SQLite, i would recommend using SQLite as it will be easy for you to understand and thus you will be able to develop your app faster.

Resources