1

私は本当に奇妙な問題に直面しています。誰かが私を助けてくれることを願っています。

CoreData セットアップで Restkit (0.20) を使用しており、responseDescriptor のすべての属性/関係マッピングをセットアップしています。初めて getObjectsAtPath:parameters を呼び出したときに正しい結果が返され、正しいオブジェクトにマップできたため、これは正しく設定されています。

ただし、後続の getObjectsAtPath 呼び出しでは、サーバーからの要求が問題なく送信され、同じ結果の JSON がクライアントに返されるのを確認できるにもかかわらず、何らかの理由で mappingResult が空の結果を返します。

誰かがこの問題を見たことがありますか??!?!!?

マッピングコードは次のとおりです。

 RKEntityMapping *userMapping = [User getEntityMapping:objectManager.managedObjectStore];
 RKEntityMapping *voteMapping = [Vote getEntityMapping:objectManager.managedObjectStore];
 RKEntityMapping *commentMapping = [Comment getEntityMapping:objectManager.managedObjectStore];
 RKEntityMapping *challengeActivityMapping = [ChallengeActivity getEntityMapping:objectManager.managedObjectStore];

// all relationship mapping
[challengeActivityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"user" toKeyPath:@"user" withMapping:userMapping]];
[challengeActivityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"votes" toKeyPath:@"votes" withMapping:voteMapping]];;
[challengeActivityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"comments" toKeyPath:@"comments" withMapping:commentMapping]];    

RKResponseDescriptor *challengeActivityResponse = [RKResponseDescriptor responseDescriptorWithMapping:challengeActivityMapping pathPattern:[ChallengeActivity restApiPathPattern] keyPath:@"challenge_activity" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[objectManager addResponseDescriptorsFromArray:[NSArray arrayWithObjects:challengeActivityResponse, userResponse, voteResponse, commentResponse, errorResponse, nil]];

各リクエストで返される JSON ペイロードは次のとおりです。

[{
  challenge_activity: {
    id: 1,
    comment: "completed this task on time!",
    image_url: null,
    created_at: "2013-05-15T00:12:21Z",
    user: {
      id: 1,
      name: "Kevin Liang",
      image_url: <some_image_url>
    },
    votes: [{
      id: 3,
      user: {
         id: 1,
         name: "Kevin Liang",
         image_url: <some_image_url>
      }
    }],
    comments: [{
      id: 1,
      text: "first comment!",
      user: {
         id: 1,
         name: "Kevin Liang",
         image_url: <some_image_url>
      }
    }]
  }
}]

フェッチコードは次のとおりです。

- (void) fetchResultsFromServerAsync
{
    [[WellifyObjectManager manager] getObjectsAtPath:[[ChallengeActivity restApiPathPattern] stringByReplacingOccurrencesOfString:@":challenge_id" withString:[NSString stringWithFormat:@"%d", 1]] parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        self.challengeActivities = [mappingResult array];
        [self.tableView reloadData];
        NSLog(@"Loaded activities");
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        NSLog(@"Hit error: %@", error);
    }];
}

これは、最初のフェッチでオブジェクトがキャッシュされていることを示しています (データが返されたので意味があります) が、2 番目のフェッチでは何も生成されず、したがってキャッシュもありません (呼び出しがサーバーに送信された場合でも)。

2013-05-19 17:41:12.844 WellifyiPhone[16147:1d903] I restkit.network:RKHTTPRequestOperation.m:154 GET 'http://0.0.0.0:3000/challenges/1/challenge_activities'
2013-05-19 17:41:12.944 WellifyiPhone[16147:1d903] I restkit.network:RKHTTPRequestOperation.m:185 GET 'http://0.0.0.0:3000/challenges/1/challenge_activities' (200 OK) [0.0999 s]
2013-05-19 17:41:12.946 WellifyiPhone[16147:21503] I restkit.core_data:RKInMemoryManagedObjectCache.m:64 Caching instances of Entity 'ChallengeActivity' by attributes 'objectId'
2013-05-19 17:41:12.951 WellifyiPhone[16147:21503] I restkit.core_data:RKInMemoryManagedObjectCache.m:64 Caching instances of Entity 'User' by attributes 'objectId'
2013-05-19 17:41:12.953 WellifyiPhone[16147:21503] I restkit.core_data:RKInMemoryManagedObjectCache.m:64 Caching instances of Entity 'Vote' by attributes 'objectId'
2013-05-19 17:41:12.955 WellifyiPhone[16147:21503] I restkit.core_data:RKInMemoryManagedObjectCache.m:64 Caching instances of Entity 'Comment' by attributes 'objectId'
2013-05-19 17:41:12.961 WellifyiPhone[16147:1d903] Loaded activities
2013-05-19 17:41:14.717 WellifyiPhone[16147:1d903] I restkit.network:RKHTTPRequestOperation.m:154 GET 'http://0.0.0.0:3000/challenges/1/challenge_activities'
2013-05-19 17:41:14.819 WellifyiPhone[16147:1d903] I restkit.network:RKHTTPRequestOperation.m:185 GET 'http://0.0.0.0:3000/challenges/1/challenge_activities' (200 OK) [0.1021 s]
2013-05-19 17:41:14.820 WellifyiPhone[16147:1d903] Loaded activities

前述したように、fetchResultsFromServerAsync メソッドが初めて呼び出されると、[mappingResult array] は ChallengeActivity の NSManagedObject を返します。ただし、後続の呼び出しでは、代わりに配列が空になります。

4

0 に答える 0