データベースから会社名と電話番号を収集する Web サービスを使用しています。ただし、電話番号が提供されない場合があります。restkit を使用して電話番号をオブジェクトにマップしようとすると、値が nil であるという警告が表示されることがあります。次に、警告メッセージが表示されます。
Coercing NSNull value to nil in shouldSetValue:atKeyPath: -- should be fixed.
nil を NSNull にマップする方法について何か提案はありますか?
これは、私の顧客関係クラス (.h) のヘッダー ファイルです。
#import <Foundation/Foundation.h>
#import <RestKit/RestKit.h>
@interface CustomerRelation : NSObject
#pragma private fields
@property (nonatomic, copy) NSString *companyName;
@property (nonatomic, copy) NSString *phoneNumber;
@end
顧客関係クラスの実装ファイル (.m)
#import "CustomerRelation.h"
@implementation CustomerRelation
-(BOOL)ValidatecompanyName:(id*)ioValue error:(NSError **)outError {
NSLog(@"error");
}
-(BOOL)validatephoneNumber:(id *)ioValue error:(NSError **)outError {
if (*ioValue == nil) {
if (outError != NULL) {
}
return NO;
}
return YES;
}
@end
これは私がマッピングを行う場所です:
- (void)viewDidAppear:(BOOL)animated{
RKObjectManager * client = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://127.0.0.1"]];
RKObjectMapping *articleMapping = [RKObjectMapping requestMapping];
[articleMapping addAttributeMappingsFromDictionary:@{@"Companyname": @"companyName",
@"Phonenumber": @"phoneNumber"}];
RKResponseDescriptor *rkresponsedesc = [RKResponseDescriptor responseDescriptorWithMapping:articleMapping method:RKRequestMethodGET pathPattern:nil keyPath:@"customers" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[client addResponseDescriptor:rkresponsedesc];
NSMutableURLRequest *request = [client requestWithObject:nil method:RKRequestMethodGET path:@"test.php" parameters:nil];
RKObjectRequestOperation *operation = [client objectRequestOperationWithRequest:request
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self mappingSuccess:mappingResult];
} failure: ^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failed with error: %@", [error localizedDescription]);
}];
[client enqueueObjectRequestOperation:operation];
MainViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"mainViewController"];
[self.navigationController pushViewController:viewController animated:YES];
}
- (void)mappingSuccess:(RKMappingResult*)mappingResult
{
NSLog(@"Success block: %@", mappingResult);
}