ios data storage and webservice query best practices? - ios

I am developing an app that fetches and pushes data to a web service and I would like to know How to do it right
My app lets the user create a "group" and add his/her friends to this group where everyone would participate in this group
My initial design got me with these Data Models
Group,
Member,
Contribution
I am thinking about using a java web backend with JSON to serialize the data before sending.
Now Here are my questions:
1-What is the best way to store my models locally on the client? is it Core Data?
2- I don`t wanna fetch the group and contributions data every time the user tries to view them, so I am thinking about adding a property to the group called groupSerial which will be increased with every change , In this way the client app will query the server for the serial and fetch the group if it is different from its local version
Is this a good idea and the best way to do it? if not what is?
3- I would like to fetch the data using HTTPS requests (GET for fetching and POST for updating) , Is this the best way to do it? any best practices to consider?
4- Is it a good idea to sub class the core data entity class and add utility methods to do relative work that involves the super class
For example I would have a core data entity class called Group , so I would make a sub class called XYZGroup that would have the following class methods
+(Group)fetchGroup:(NSString gid); // return the latest version of the group ,whether from local storage or the web server
+(void)newGroup:(Group)group; //push the new group to the web server and update local data
+(NSArray)getGroupsSummaries;//Return an array of meta data about joined groups
Also , I would have a class called XYZMember that would have some methods like:
+(NSString)myMemberID;
+(NSArray)getMembers:(NSArray)numbersInContacts;//Takes a list of phone numbers and returns an array of members that have the app installed
5-Do I need additional entity classes to store the data locally , for example: Do I need a core data entity class called Mygroups that would have an array of the groups the user is currently in
Thank you very much

1, if you want to store lightweight data only, json is better than core data.
2, it depends what you implement web service and what you want to export
3, you can use WSDL xml file and use WSDLParser.app to generate obj-c code.
4, up to you
5, up to you

Related

In firebase, how to create a user and add data in user object from ESP 8266?

I'm working with some IoT projects and for handling all data I have used Blynk application but now I have created my own app but problem is that I want to add sensor data to firebase, but I have multiple users that's why I want to separate my data for every user, how can i do this, which Library is helpful for this? I have searched on Google for this, but everyone adding data in common database but how to separate the data for multiple users?
To separate data per user in your database, you will want to organize the database reference path to a location relevant to the user uid. if your app supports Auth, you can access this with the currentUser object which should have their uid as a property.

Best design pattern to handle iOS Application State/Data

I am starting a new project (learning purposes) and I am trying to figure out what is the best software design pattern to use in the following scenario.
I have several data that need to be downloaded from multiple webservices and store somewhere in my app, to display it later. However each piece of data (e.g. list of teachers, students) will only be used in one or more specific view controllers (e.g. teachersViewController and studentsViewController).
I read that the Singleton pattern or use the AppDelegate to store a variable (an object like ApplicationData) is a bad practise, even more in this example which I want to restrict the data access.
So, which design pattern should I choose? I have read something about dependency injection, but I don't have any clue about it or if it even helps me in this question. If it helps, some examples with explanation would be nice.
You need some sort of database to store downloaded data. Good choices are Realm and Core Data. The right way to process data is:
Check if data is already in DB and show it if available.
Download or update data from server and parse it to objects.
Save objects to DB.
Show data taken from DB to user.
Download data as needed. When you open VC with students then download only students data and so on.
EDITED: If you need all the data on app open then load it and put in a DB before first screen opens. Then just use DB to show data to user.

Core Data Values Accessed by Multiple Users when logged in (iOS Swift)

I have an app where a UITableView is used to represent a friends list. Now, this table is updated by values stored in core data, and I'm downloading friend values to core data via Parse. Instead of accessing Parse to update the tableView directly, I decided to update Core Data and then the tableView because I need the friend information in other parts of the app, and thought it would be more efficient to use Core Data than to have calls to Parse again and again. Everything works fine!
However, my app has a log in system before users can use the app. And when I created another dummy user to test it, I found that the friend values stored in Core Data by my actual account were being used to update the friend list tableView! When actually the tableView should be empty (new user).
I don't know exactly how Core Data works but I figure it uses some segment of the device's memory to store entities. My question is this, is it possible to use Core Data to store private information related to a particular user that can't be accessed by other users that log into the same device? Or should I continue to make calls to Parse whenever I need information?
Hope you guys understood my question, thanks!
iOS is not a multi-user system. Your app stores its files in a sandboxed folder structure and this sandbox is independent of any user logins you have implemented in your app.
When a new user logs in (or, if you prefer, when a user logs out) it is up to you to remove any data you have stored in Core Data that you don't want another user to have access to.
Parse can save data offline by Local Storage or cache the request by Cache Policy
They are much faster than creating your own database (by CoreData).

App structure iOS and Realm: create database when app is installed

I am very new to iOS. I am developing an app with data persistence. I have decided to use Realm for that purpose.
I must to create the database and load data the first time that app runs. I get data from a Web Service in JSON format. I will implement some strategy to update this database later, maybe with iOS Silent Push notifications.
I have read and I have worked about Realm, loading data from JSON... to learn about that.
Now, I need to apply this in my project but I don't know how to start. I need some clues about general idea for the app:
How can I organize my app to load data when it is installed? At what point should I create the database and load data?
I have thought to create a global Realm object y AppDelegate and use it as a global variable. Is it a good idea?
Do I need to set a path for my database? Can I user default path?
If you are looking for a place to start, you can check out the example apps of this UI component add-on for Realm: ABFRealmGridController.
The controller is a subclass of UICollectionView and the example app should demonstrate most of the functionality you are curious about. The example uses the controller to display the top news stories from the New York Times. This involves making a request to their API and loading the JSON response data into Realm.
When to load the data is dependent on how you want the app to function. If the data will be the same for each user, you could bundle the Realm file with the app pre-populated with data.
The ABFRealmGridController example loads data when the user clicks the refresh button and performs the JSON handling on a background thread; a general best-practice.
Finally, unless you have multiple Realms or need to store the file in a specific path, it is probably simplest to use the default path.

AFIncrementalStore to sync Core Data with REST API

I was wondering if you have ever used AFIncrementalStore to sync between Core Data and a REST API? And if you so, it is a good approach to use it without the Heroku Core Data Buildpack? I don't like dark magic :P
My Core Data model might not match exactly the REST API.
AFIncrementalStore works fine with a simple REST API.
You may have to override the representationForResponse method for a fine match with your models but it should be all that is needed (except from the init part of course)
My advice: make an exact match between the API and your CoreData models and then use categories to generate the data the way you want them.
I'm currently doing an e-commerce app and my API send me products with an expiration_date which is a unix timestamp. I save as it is in CoreData and then I have a category on my NSManagedObject Product methods like hoursRemaining, weeksFromNow and so on for an easier display in the UI.
For the relationships, I'm not use those for automatic fetching with AFIncrementalStore so I can't say much.

Resources