Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you map AFIncrementalStore to Twitter API v1.1?

How do you map AFIncrementalStore to Twitter API v1.1?


Core Data Persistence with AFNetworking, Done Right

https://github.com/AFNetworking/AFIncrementalStore

REST API v1.1 Resources

https://dev.twitter.com/docs/api/1.1


- (id)representationOrArrayOfRepresentationsOfEntity:(NSEntityDescription *)entity
                                  fromResponseObject:(id)responseObject;

- (NSDictionary *)representationsForRelationshipsFromRepresentation:(NSDictionary *)representation
                                                           ofEntity:(NSEntityDescription *)entity
                                                       fromResponse:(NSHTTPURLResponse *)response;

- (NSString *)resourceIdentifierForRepresentation:(NSDictionary *)representation
                                         ofEntity:(NSEntityDescription *)entity
                                     fromResponse:(NSHTTPURLResponse *)response;

- (NSDictionary *)attributesForRepresentation:(NSDictionary *)representation
                                     ofEntity:(NSEntityDescription *)entity
                                 fromResponse:(NSHTTPURLResponse *)response;

- (NSMutableURLRequest *)requestForFetchRequest:(NSFetchRequest *)fetchRequest
                                    withContext:(NSManagedObjectContext *)context;

- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
                       pathForObjectWithID:(NSManagedObjectID *)objectID
                               withContext:(NSManagedObjectContext *)context;

- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
                       pathForRelationship:(NSRelationshipDescription *)relationship
                           forObjectWithID:(NSManagedObjectID *)objectID
                               withContext:(NSManagedObjectContext *)context;
like image 644
Zelko Avatar asked Nov 01 '22 21:11

Zelko


1 Answers

I do not know if what i write is exactly helpful, but here is what i know:

AFIncrementalStore has some serious issues and is apparently abandoned by it's creator as it is incompatible with AFNetworking v. 2

The issues arise from the fact that AFIS tries to be more than an incremental store. Incremental store operates only inside its overriden methods and AFIS does this to immediately return objects from the backing store. However, when request finally comes in it cannot add objects this way. It adds them to the backing store and then tries to refresh the objects in their contexts. This behaviour was not evisioned by Core Data creators and results in unstable behaviour - AFIS sometimes has very long response times and sometimes objects do not refresh properly. Furthermore, if you use NSFetchedResultsController to feed table views, some callbacks are called often ans some never.

I spent a lot of time trying to get this working but it probably is impossible - you have to cheat core data that you are adding objects to the context while never doing so.

And back to your question - if you really want to use it - you basically have to write all those methods for twitter. This is a hard job but twitter has to have some object model and some id's assigned to each object. I did this for my API's but it's like one or two days of hard work - and i do not have so much time to write it here.

like image 64
Terminus Avatar answered Nov 15 '22 06:11

Terminus