0

RestKit にはかなり慣れていないので、パブリック Gist データをダウンロードするときに問題が発生します。

そのような対応するオブジェクトを持つ 1RKObjectManagerつと 2 つのオブジェクトを作成しました。RKResponseDescriptorRKEntityMapping

RKEntityMapping *userEntityMapping = [RKEntityMapping mappingForEntityForName:@"User" inManagedObjectStore:managedObjectStore];
userEntityMapping.identificationAttributes = @[@"userID"];
[userEntityMapping addAttributeMappingsFromDictionary:@{
 @"id"          : @"userID",
 @"avatar_url"  : @"avatarURL",
 @"gravatar_id" : @"gravatarID",
 @"url"         : @"jsonURL",
 @"login"       : @"login"}];

RKResponseDescriptor *userResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:userEntityMapping pathPattern:@"/gists/public" keyPath:@"user" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[objectManager addResponseDescriptor:userResponseDescriptor];

// Gist Entity
RKEntityMapping *gistEntityMapping = [RKEntityMapping mappingForEntityForName:@"Gist" inManagedObjectStore:managedObjectStore];
gistEntityMapping.identificationAttributes = @[ @"gistID" ];
[gistEntityMapping addRelationshipMappingWithSourceKeyPath:@"user" mapping:userEntityMapping];
[gistEntityMapping addAttributeMappingsFromDictionary:@{
 @"id":             @"gistID",
 @"url":            @"jsonURL",
 @"description":    @"descriptionText",
 @"public":         @"public",
 @"created_at":     @"createdAt"}];

RKResponseDescriptor *gistResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:gistEntityMapping pathPattern:@"/gists/public" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[objectManager addResponseDescriptor:gistResponseDescriptor];

この問題は、json のユーザー フィールドが null になることがあり、それに対処する方法がわからないという問題から発生します。実際、私はここで例外を得ました

static NSDictionary *RKEntityIdentificationAttributesForEntityMappingWithRepresentation(RKEntityMapping *entityMapping, NSDictionary *representation)

ここで処理された配列に null 値が含まれていることがわかり、例外が発生しました。

- (NSArray *)mapRepresentations:(id)representations atKeyPath:(NSString *)keyPath usingMapping:(RKMapping *)mapping

それらの状況を処理する方法はありますか?

編集:

例外は

NSCAssert([表現 isKindOfClass:[NSDictionary クラス]], @"辞書表現が必要です");

RKManagedObjectMappingOperationDataSource

static NSDictionary *RKEntityIdentificationAttributesForEntityMappingWithRepresentation(RKEntityMapping *entityMapping, NSDictionary *representation)

JSONに関する限り、時々このように見えます。

{
"url": "https://api.github.com/gists/5661319",
"forks_url": "https://api.github.com/gists/5661319/forks",
"commits_url": "https://api.github.com/gists/5661319/commits",
"id": "5661319",
"git_pull_url": "https://gist.github.com/5661319.git",
"git_push_url": "https://gist.github.com/5661319.git",
"html_url": "https://gist.github.com/5661319",
"files": {
  "header.php": {
    "filename": "header.php",
    "type": "application/httpd-php",
    "language": "PHP",
    "raw_url": "https://gist.github.com/raw/5661319/12598e6d41015248235058cda806722b30f81dca/header.php",
    "size": 173
  }
},
"public": true,
"created_at": "2013-05-28T08:29:35Z",
"updated_at": "2013-05-28T08:29:36Z",
"description": "",
"comments": 0,
"user": null,
"comments_url": "https://api.github.com/gists/5661319/comments"

}、

4

0 に答える 0