Different json object on every request - ios

I'm trying to create an iOS application with Github activity feed in the table or in the collection view.
The endpoint I'm hooking at is here.
And the API Doc is here
I can create Swift native objects depend on JSON but there has been written in API doc that payload object is different based on state. There is approximately a different 40 payload object.
How can I parse this type of json? Where the object is different on every request.
Should I create 40 different objects? I think it is not a smart way to do it.

Related

Deleting objects from REST API

I currently have an api call that gives me an array of featured series for a video streaming app. If one of these series gets deleted it seems realm won't delete the object if it is gone from the JSON REST response. Core Data does it so is there something I am missing with realm?
When you check your REST API you will need to delete any objects that no longer exist. A way to do this is to check what is in Realm against the primary keys you get from your REST api. If it doesn't exist, delete that object.
This isn't something that Realm does automatically since it has no way of knowing what has been deleted on your server.

how to store data locally

So i have no idea how to manipulate data effectively. Currently I am querying all my data (messages) from my backend and manipulating it within the view controller file and passing it among view controllers via segues. I realize this is probably ridiculous for a messaging app.
I am thinking of making a separate file called data in order to manipulate the data effectively. The data consists of the message body, object id, sender name, sender id, and time stamp. I was also planning on making custom classes to handle this data.
Would it be best to take this route and how do I effectively manipulate data from other view controllers?
You should use SQLite to save all data.You can create a new table and query all data.It's easy to learn and use.Good luck.

RestKit / Core Data / Offline - Do I need UUID or is RestKit smart enough?

I'm having an app that saves Core Data objects to the local store for immediate or later POST to an API.
My guess was that I would get duplicate objects: (1) the object created locally and sent to the POST method and (2) one that is created when mapping the object returned from the POST call.
But RestKit seems to find the original object even if I don't have any universal identification? How can this work? I can't find any of this in the source code which makes me a little bit confused and I don't know if I can depend on this.
So:
When storing objects in Core Data and later POSTing them with RestKit, do I need an UUID so RestKit can map the actual posted object with the one returned with the POST request?
Or can I depend on Rest Kit always maps the response of the POST call to the object I sent as an argument to the POST method?
When you POST an object, RestKit does not try to create a new object as the destination of the response mapping. It explicitly updates the supplied object that is being POSTed. You don't need to have a special identifier and you don't need to already have the object in Core Data.

How can I request a managed object in RestKit without it writing it back to the Managed Object Context?

I'm writing a login sequence for an iOS app and I'm using the following path to request user information:
"profiles/:email" (RKRequestMethodGET)
Unfortunately I also have to use this path to check if a certain e-mail address has already been taken as well.
My question is, how do I prevent RestKit from updating/inserting an Account object into the Managed Object Store when I already have an Entity Response Mapping in place for that path? Is there a way to tell the RK request that is shouldn't do any mapping to the Managed Object Store but still report back to me that a successful mapping has occurred?
Not really.
You could have 2 different RKObjectManager instances, 1 that is used for Core Data and actually updating and managing the users. The other is used without Core Data and just for validation. This allows the 2 different object managers to have different response descriptors.
An alternative would be to add and remove the response descriptors depending on what requests you're making. But, this is messy and potentially error prone.

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