Search code examples
ioscore-dataafincrementalstore

AFIncrementalStore with AFRestClient > Overriding resourceidentifier in my AFRestClient subclass doesn't work for me


My HTTPClient is an AFRESTClient subclass and I am using AFIncrementalStore for Core data.

My response is having a unique identifier as "content_id" for the entity. I have overridden

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

in my httpclient and returned "content_id" for my entity, however, my fetch just gets only one item (last item in the array).

However if my response has "id" parameter it works fine.

Should we not able to override resourceIdentifier for a rest client or am I missing something ?


Solution

  • I figured it out finally

    I was returning a constant string value for the resourceIdentifier, where I should be returning the stringified unique value.

    Now I am returning the description of the unique value and works fine

    - (NSString *)resourceIdentifierForRepresentation:(NSDictionary *)representation
                                             ofEntity:(NSEntityDescription *)entity
                                         fromResponse:(NSHTTPURLResponse *)response
    {
        NSString *resourceIdentifier = [super resourceIdentifierForRepresentation:representation ofEntity:entity fromResponse:response];
    
        if([entity.name isEqualToString:@"MyEntity"])
        {
            resourceIdentifier = [[representation objectForKey:CONTENT_ID] description];
        }
        return resourceIdentifier;
    }
    

    previously I returned resourceIdentifier = CONTENT_ID

    Thanks to Matt Thompson for clarifying here - (See the comment by Matt) https://github.com/AFNetworking/AFIncrementalStore/issues/211