첨부 된 이미지가있는 새 사용자를 만들기 위해 다중 부분 POST를 수행하려고합니다. RKMappingResult
은 응답을 성공적으로 매핑했음을 보여 주지만, 어떤 이유로 인해 User
엔티티 개체에 올바르게 매핑되지 않습니다. 이러한 모든 특성은 매핑 이후에 여전히 nil
이기 때문입니다.RestKit 매핑 결과가 채워지지만 Core Data 엔터티가 설정되지 않았습니다.
RKMappingResult : (매핑 후)
(lldb) po mappingResult
<RKMappingResult: 0xc8d04a0, results={
user = "<User: 0xc8d4360> (entity: User; id: 0xc676560 <x-coredata://68DA437E-D836-48F7-B4CE-CC08EC38B98F/User/p15> ; data: {\n accessToken = c81453227a39e16e396218d3a1ef0d80;\n actions = nil;\n createdAt = \"2013-12-11 15:34:45 +0000\";\n email = \"[email protected]\";\n firstName = Some;\n fullName = \"Some User\";\n lastName = User;\n timezone = nil;\n updatedAt = \"2013-12-11 15:34:45 +0000\";\n username = nil;\n uuid = \"de565267-eaf9-4cbf-a63e-44dd7df405aa\";\n})";
}>
코어 데이터 User
법인 :
(lldb) po newUser
<User: 0xc8ac300> (entity: User; id: 0xc8c5050 <x-coredata:///User/t1251A6D9-8FB8-4AF2-AFA4-ADB61F39397F2> ; data: {
accessToken = nil;
actions = nil;
createdAt = nil;
email = nil;
firstName = nil;
fullName = "(null) (null)";
lastName = nil;
timezone = nil;
updatedAt = nil;
username = nil;
uuid = nil;
})
코드 :
User *newUser = [User createNewUser];
NSDictionary *userParams = @{kJsonUser : params};
NSURLRequest *request = [[APIClient objectManager] multipartFormRequestWithObject:newUser method:RKRequestMethodPOST path:kEndPointCreateListUsers parameters:userParams constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
UIImage *image = [params objectForKey:kJsonImage];
if (image) {
[formData appendPartWithFileData:UIImageJPEGRepresentation(image, 1.0)
name:@"user_image"
fileName:@"user_image.jpeg"
mimeType:@"image/jpeg"];
}
}];
RKManagedObjectRequestOperation *operation = [[APIClient objectManager] managedObjectRequestOperationWithRequest:request managedObjectContext:[APIClient mainThreadContext] success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self handleSignUpSuccessForUser:newUser];
success([newUser uuid]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
[self handleSignUpFailure];
failure([error localizedDescription]);
}];
[[APIClient objectManager] enqueueObjectRequestOperation:operation];
내가 발견 한 한 가지입니다 메모리 주소 매핑 결과에 User
가 다른 경우 newUser
개체. 정상적인 (멀티 파트가 아닌) 요청을 사용하면 잘 매핑되고 Core Data 객체가 설정됩니다.
제공 할 수있는 도움이 있으면 대단히 감사하겠습니다. 매핑 결과에서
빠른 응답을 보내 주셔서 감사합니다. '(APIClient objectManager에 저장되어있는)'RKObjectManager'가 그것을 삭제하고 매핑 결과를 사용하는 대신에'newUser'를 업데이트 할 수 있도록 요청을 만드는 더 좋은 방법이 있습니까? – ZeNewb
이미지 데이터를 보내고 있기 때문에 그렇게 생각하지 않습니다. 이미지가 전송되지 않고 있습니다. – Wain
쿨, 잘 도와 줘서 고마워! 나는 더 이상 객체를 전달하지 않고 새로 생성 된 사용자를 얻기 위해'User * newUser = [mappingResult firstObject];'를 사용합니다. – ZeNewb