0

ここでRestKitのドキュメントに従った後、オブジェクトマッピングが成功しました。ワフー!私の質問は、プロジェクト全体でこのオブジェクトにアクセスするにはどうすればよいですか?RestKitを使用してJSON応答をAPIUserオブジェクトにマップしました。たとえば、次の画面で、APIUserオブジェクトからユーザーの名を取得して挨拶します。そのオブジェクトにアクセスするにはどうすればよいですか?

私はObjective-cを初めて使用するので、RestKitフレームワークよりも、グローバルオブジェクトシングルトンクラス、およびObjective-Cのクラス間でのデータの永続化に関する質問の方が多いでしょう。

ここに投稿されているのは、参照に役立つ場合に備えて、私のレストキットオブジェクトマッピングログです。ありがとう。どんな助けでも大歓迎です。

2012-07-30 14:54:04.813 TestApp[2361:1a707] D restkit.object_mapping:RKObjectMapper.m:240 Performing object mapping sourceObject: {
    apiUser =     {
        active = 1;
        apiUserIdx = 101;
        birthdate = "1980-06-21T00:00:00-06:00";
        countryCode = US;
        firstName = "test_user1_firstname";
        lastName = "test_user1_lastname";
        ssn = 1111;
        userName = "test_user1";
        verified = 1;
    };
}
 and targetObject: (null)
2012-07-30 14:54:04.813 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMapper.m:254 Examining keyPath 'errors' for mappable content...
2012-07-30 14:54:04.813 TestApp[2361:1a707] D restkit.object_mapping:RKObjectMapper.m:264 Found unmappable value at keyPath: errors
2012-07-30 14:54:04.814 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMapper.m:254 Examining keyPath 'apiUser' for mappable content...
2012-07-30 14:54:04.814 TestApp[2361:1a707] D restkit.object_mapping:RKObjectMapper.m:283 Found mappable data at keyPath 'apiUser': {
    active = 1;
    apiUserIdx = 101;
    birthdate = "1980-06-21T00:00:00-06:00";
    countryCode = US;
    firstName = "test_user1_firstname";
    lastName = "test_user1_lastname";
    ssn = 1111;
    userName = "test_user1";
    verified = 1;
}
2012-07-30 14:54:04.814 TestApp[2361:1a707] D restkit.object_mapping:RKObjectMapper.m:189 Asked to map source object {
    active = 1;
    apiUserIdx = 101;
    birthdate = "1980-06-21T00:00:00-06:00";
    countryCode = US;
    firstName = "test_user1_firstname";
    lastName = "test_user1_lastname";
    ssn = 1111;
    userName = "test_user1";
    verified = 1;
} with mapping RKObjectMapping class => APIUser: keyPath mappings => (
    "RKObjectKeyPathMapping: lastName => lastName",
    "RKObjectKeyPathMapping: birthdate => birthdate",
    "RKObjectKeyPathMapping: countryCode => countryCode",
    "RKObjectKeyPathMapping: firstName => firstName",
    "RKObjectKeyPathMapping: password => password",
    "RKObjectKeyPathMapping: apiUserIdx => apiUserIdx",
    "RKObjectKeyPathMapping: active => active",
    "RKObjectKeyPathMapping: userName => userName",
    "RKObjectKeyPathMapping: verified => verified"
)
2012-07-30 14:54:04.815 TestApp[2361:1a707] D restkit.object_mapping:RKObjectMappingOperation.m:428 Starting mapping operation...
2012-07-30 14:54:04.816 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:242 Mapping attribute value keyPath 'lastName' to 'lastName'
2012-07-30 14:54:04.816 TestApp[2361:1a707] D restkit.object_mapping:RKObjectPropertyInspector.m:95 Cached property names and types for Class 'APIUser': {
    accessibilityHint = NSString;
    accessibilityLabel = NSString;
    accessibilityLanguage = NSString;
    accessibilityValue = NSString;
    birthdate = NSDate;
    countryCode = NSString;
    firstName = NSString;
    lastName = NSString;
    password = NSString;
    userName = NSString;
}
2012-07-30 14:54:04.818 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:252 Mapped attribute value from keyPath 'lastName' to 'lastName'. Value: test_user1_lastname
2012-07-30 14:54:04.818 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:242 Mapping attribute value keyPath 'birthdate' to 'birthdate'
2012-07-30 14:54:04.818 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:115 Found transformable value at keyPath 'birthdate'. Transforming from type '__NSCFString' to 'NSDate'
2012-07-30 14:54:04.818 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:97 Transforming string value '1980-06-21T00:00:00-06:00' to NSDate...
2012-07-30 14:54:04.819 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:259 Skipped mapping of attribute value from keyPath 'birthdate to keyPath 'birthdate' -- value is unchanged ((null))
2012-07-30 14:54:04.821 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:242 Mapping attribute value keyPath 'countryCode' to 'countryCode'
2012-07-30 14:54:04.822 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:252 Mapped attribute value from keyPath 'countryCode' to 'countryCode'. Value: US
2012-07-30 14:54:04.822 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:242 Mapping attribute value keyPath 'firstName' to 'firstName'
2012-07-30 14:54:04.822 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:252 Mapped attribute value from keyPath 'firstName' to 'firstName'. Value: test_user1_firstname
2012-07-30 14:54:04.822 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:291 Did not find mappable attribute value keyPath 'password'
2012-07-30 14:54:04.823 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:242 Mapping attribute value keyPath 'apiUserIdx' to 'apiUserIdx'
2012-07-30 14:54:04.839 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:252 Mapped attribute value from keyPath 'apiUserIdx' to 'apiUserIdx'. Value: 101
2012-07-30 14:54:04.840 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:242 Mapping attribute value keyPath 'active' to 'active'
2012-07-30 14:54:04.840 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:252 Mapped attribute value from keyPath 'active' to 'active'. Value: 1
2012-07-30 14:54:04.840 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:242 Mapping attribute value keyPath 'userName' to 'userName'
2012-07-30 14:54:04.840 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:252 Mapped attribute value from keyPath 'userName' to 'userName'. Value: test_user1
2012-07-30 14:54:04.841 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:242 Mapping attribute value keyPath 'verified' to 'verified'
2012-07-30 14:54:04.845 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMappingOperation.m:252 Mapped attribute value from keyPath 'verified' to 'verified'. Value: 1
2012-07-30 14:54:04.845 TestApp[2361:1a707] D restkit.object_mapping:RKObjectMappingOperation.m:434 Finished mapping operation successfully...
2012-07-30 14:54:04.846 TestApp[2361:1a707] T restkit.object_mapping:RKObjectMapper.m:254 Examining keyPath 'error' for mappable content...
2012-07-30 14:54:04.846 TestApp[2361:1a707] D restkit.object_mapping:RKObjectMapper.m:264 Found unmappable value at keyPath: error
2012-07-30 14:54:04.846 TestApp[2361:1a707] D restkit.object_mapping:RKObjectMapper.m:304 Finished performing object mapping. Results: {
    apiUser = "<APIUser: 0xcd8b170>";
}
4

1 に答える 1

0

私はそれを理解したと思います。APIUser の新しいインスタンスを作成し、次のように設定する必要がありまし[objects objectAtIndex:0]. た。

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {

    NSLog(@"There are %i objects.", objects.count);

    APIUser *apiUser = [objects objectAtIndex:0];
    NSLog(@"Loaded apiUserIdx #%i -> First name: %@, Last name: %@", apiUser.apiUserIdx, apiUser.firstName, apiUser.lastName);

}
于 2012-07-30T21:40:07.920 に答える