5

你如何映射AFIncrementalStore到 Twitter API v1.1?


使用 AFNetworking 实现核心数据持久性,做得对

https://github.com/AFNetworking/AFIncrementalStore

REST API v1.1 资源

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;
4

1 回答 1

2

我不知道我写的是否真的有帮助,但这是我所知道的:

AFIncrementalStore 有一些严重的问题,显然被它的创建者抛弃了,因为它与 AFNetworking v. 2 不兼容

问题源于 AFIS 试图不仅仅是增量存储这一事实。增量存储仅在其覆盖的方法内运行,AFIS 这样做是为了立即从后备存储返回对象。但是,当请求最终进来时,它不能以这种方式添加对象。它将它们添加到后备存储中,然后尝试刷新其上下文中的对象。Core Data 创建者没有预见到这种行为,并导致行为不稳定 - AFIS 有时响应时间很长,有时对象无法正确刷新。此外,如果您使用 NSFetchedResultsController 来提供表格视图,则某些回调会经常被调用,而有些则永远不会。

我花了很多时间试图让这个工作,但这可能是不可能的——你必须欺骗核心数据,你正在向上下文添加对象,而从不这样做。

回到你的问题——如果你真的想使用它——你基本上必须为 twitter 编写所有这些方法。这是一项艰巨的工作,但 twitter 必须有一些对象模型和一些 id 分配给每个对象。我为我的 API 做了这个,但这就像一两天的艰苦工作——而且我没有太多时间在这里写它。

于 2014-08-02T07:13:25.363 回答