3

オブジェクトにマップしようとしていますが、取得し続けます

[<ItemObject 0x100353710> valueForUndefinedKey:]: this class is not key value coding-compliant for the key uid.

ItemObject.h

@interface ItemObject : NSObject

@property (nonatomic, retain) NSNumber * uid;
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * itemType;

@end

ItemObject.m

@implementation ItemObject

@dynamic uid;
@dynamic title;
@dynamic itemType;

@end

方法

+ (void)searchFeatureById:(NSString *)searchId
{
    NSLog(@"Search Feature By ID: %@", searchId);
    RKObjectMapping *itemMapping = [RKObjectMapping mappingForClass:[ItemObject class]];

    [itemMapping addAttributeMappingsFromDictionary:@{
     @"id": @"uid",
        @"name": @"title",
        @"item_type": @"itemType"
     }];


    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:itemMapping pathPattern:nil keyPath:@"data" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

    RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]];
    // The entire value at the source key path containing the errors maps to the message
    [errorMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"errorMessage"]];
    NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError);
    // Any response in the 4xx status code range with an "errors" key path uses this mapping
    RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping pathPattern:nil keyPath:@"error_description" statusCodes:statusCodes];
    RKObjectManager *manager = [RKObjectManager sharedManager];
    NSLog(@"HTTP Client: %@", manager.HTTPClient);

    [manager addResponseDescriptorsFromArray:@[ responseDescriptor, errorDescriptor ]];
//    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"false", @"with_lock"
                            , nil];
    NSString *path = [NSString stringWithFormat:@"/api/v1/features/%@", searchId];
    NSLog(@"Manager: %@", manager);
    [manager getObjectsAtPath:path parameters:params success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
        NSLog(@"Results: %@", result);
        // Handled with articleDescriptor
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        // Transport error or server error handled by errorDescriptor
        NSLog(@"Error: %@", [error localizedDescription]);
        NSAlert *alert = [NSAlert alertWithMessageText:@"Error" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", [error localizedDescription]];
        [alert runModal];

    }];
}

JSON応答

{
    "data": {
        "id": 1961,
        "item_type": "features",
        "assigned_to": {
        "id": 106
    },
    "parent": {
        "id": 0
    },
        "priority": {
        "id": 3
    },
        "project": {
        "id": 62
    },
        "release": {
        "id": 180
    },
        "reported_by": {
        "id": 106
    },
        "reported_by_customer_contact": {
        "id": 0
    },
        "status": {
        "id": 6
    },
        "workflow_step": {
        "id": 10
    },
        "actual_duration": {
        "duration": 0,
        "time_unit": {
            "id": 2
        }
    },
        "estimated_duration": {
        "duration": 8,
        "time_unit": {
            "id": 2
        }
    },
        "remaining_duration": {
        "duration": 0,
        "time_unit": {
            "id": 2
        }
    },
        "percent_complete": 0,
        "archived": false,
        "publicly_viewable": false,
        "completion_date": "1899-01-01T07:00:00Z",
        "due_date": "1899-01-01T07:00:00Z",
        "start_date": "2013-03-11T07:00:00Z",
        "description": "Create Login GUI",
        "name": "Login View",
        "notes": "",
        "number": "1961",
        "build_number": "",
        "custom_fields": {
            "custom_157": true,
            "custom_180": "",
            "custom_174": "",
            "custom_181": false,
            "custom_179": "",
            "custom_182": "",
            "custom_186": false,
            "custom_156": 0,
            "custom_161": "",
            "custom_163": "",
            "custom_164": "",
            "custom_165": "",
            "custom_167": "",
            "custom_185": []
        }
    }
}

クラッシュ

(
    0   CoreFoundation                      0x00007fff8d39bf56 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff8a7b2d5e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8d4261b9 -[NSException raise] + 9
    3   Foundation                          0x00007fff9716c703 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 240
    4   Foundation                          0x00007fff970a338e _NSGetUsingKeyValueGetter + 108
    5   Foundation                          0x00007fff970a3315 -[NSObject(NSKeyValueCoding) valueForKey:] + 392
    6   Foundation                          0x00007fff970c2da2 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 348
    7   RestKit                             0x0000000100079675 -[RKMappingOperation shouldSetValue:atKeyPath:] + 85
    8   RestKit                             0x000000010007ad9f -[RKMappingOperation applyAttributeMapping:withValue:] + 2079
    9   RestKit                             0x000000010007c028 -[RKMappingOperation applyAttributeMappings:] + 1752
    10  RestKit                             0x00000001000832e0 -[RKMappingOperation main] + 3200
    11  Foundation                          0x00007fff970c56b4 -[__NSOperationInternal start] + 705
    12  RestKit                             0x000000010006c84e -[RKMapperOperation mapRepresentation:toObject:atKeyPath:usingMapping:metadata:] + 1870
    13  RestKit                             0x000000010006afbb -[RKMapperOperation mapRepresentation:atKeyPath:usingMapping:] + 1883
    14  RestKit                             0x000000010006da20 -[RKMapperOperation mapRepresentationOrRepresentations:atKeyPath:usingMapping:] + 832
    15  RestKit                             0x000000010006e26e -[RKMapperOperation mapSourceRepresentationWithMappingsDictionary:] + 1966
    16  RestKit                             0x000000010006ebbf -[RKMapperOperation main] + 1375
    17  Foundation                          0x00007fff970c56b4 -[__NSOperationInternal start] + 705
    18  RestKit                             0x00000001000e8f1c -[RKObjectResponseMapperOperation performMappingWithObject:error:] + 1116
    19  RestKit                             0x00000001000e7347 -[RKResponseMapperOperation main] + 2055
    20  Foundation                          0x00007fff970c56b4 -[__NSOperationInternal start] + 705
    21  Foundation                          0x00007fff970d8912 ____NSOQSchedule_block_invoke_2 + 124
    22  libdispatch.dylib                   0x00007fff8abe1a82 _dispatch_call_block_and_release + 18
    23  libdispatch.dylib                   0x00007fff8abe2961 _dispatch_worker_thread2 + 255
    24  libsystem_c.dylib                   0x00007fff9054c3da _pthread_wqthread + 316
    25  libsystem_c.dylib                   0x00007fff9054db85 start_wqthread + 13

MacOSX開発にRestKit0.20.0-rc1を使用する

私は何が間違っているのですか?オブジェクトのプロパティを追加/削除すると、新しいパラメータに対して同じキー/値エラーがスローされます。これは、それが私のオブジェクトではなく、おそらくキーパスであると私に信じさせますか?

アップデート

RKMappingOperation.mファイル行356にジャンプします。

- (BOOL)shouldSetValue:(id *)value atKeyPath:(NSString *)keyPath
{
    id currentValue = [self.destinationObject valueForKeyPath:keyPath]; //<-- this line here
    if (currentValue == [NSNull null]) {
        currentValue = nil;
    }

@noaごとに2を更新

2013-03-14 10:11:51.012 Project[55798:6a03] Destination Class: ItemObject
2013-03-14 10:11:51.012 Project[55798:6a03] Destination Class Super: NSObject

追加する

[self.destinationObject objectForKey:@"uid"];

ログ

2013-03-14 10:16:08.030 Project[55836:2203] -[ItemObject objectForKey:]: unrecognized selector sent to instance 0x103437e80
4

1 に答える 1

3

実装で使用しているディレクティブは、そのプロパティのメソッドを生成しない@dynamicようにコンパイラーに指示します。これらのメソッドは存在しないため、クラスはこれらのキーのKey-Valueに準拠していません。(つまり、RestKitはメソッドを呼び出そうとしていますが、存在しません。)uid

次のいずれかを行う必要があります。

  • @dynamic宣言を削除します(コンパイラが必要なメソッドを合成するようにします)または
  • uidおよびの独自の実装を追加しますsetUid:
于 2013-03-14T17:29:18.257 に答える