"Person"이라는 엔티티를 만들었습니다. 다음은 엔터티의 특성입니다.컨텍스트 마법 기록에 문제 저장 사용자 지정 유효성 검사 도중 핵심 데이터
@property (nonatomic, retain) NSString * address;
@property (nonatomic, retain) NSString * confirmPassword;
@property (nonatomic, retain) NSString * createdOn;
@property (nonatomic, retain) NSString * email;
@property (nonatomic, retain) NSString * fbId;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * password;
@property (nonatomic, retain) NSString * phNumber;
@property (nonatomic, retain) NSString * sessionToken;
사용자 정의 유효성 검사는 "confirmPassword"와 같은 "비밀"이 개 속성에 추가됩니다
- (BOOL)validatePassword:(id *)ioValue error:(NSError **)outError {
// Password's validation is not specified in the model editor, it's specified here.
// field width: min 4, max 32
BOOL isValid = YES;
NSString *password = *ioValue;
NSString *errorMessage;
NSInteger code = 0;
if (password.length == 0) {
errorMessage = @"Please enter password.";
code = NSValidationMissingMandatoryPropertyError;
isValid = NO;
} else if (password.length < 4) {
errorMessage = @"Password can't be less than 4 characters.";
code = NSValidationStringTooLongError;
isValid = NO;
} else if (password.length > 32) {
errorMessage = @"Password can't be more than 32 characters.";
code = NSValidationStringTooLongError;
isValid = NO;
}
if (outError && errorMessage) {
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : errorMessage };
NSError *error = [[NSError alloc] initWithDomain:kHAB
code:code
userInfo:userInfo];
*outError = error;
}
return isValid;
}
- (BOOL)validateConfirmPassword:(id *)ioValue error:(NSError **)outError {
// Confirm Password's validation is not specified in the model editor, it's specified here.
// field validation
BOOL isValid = YES;
NSString *confirmPassword = *ioValue;
NSString *errorMessage;
NSInteger code = 0;
if (![confirmPassword isEqualToString:self.password]) {
errorMessage = @"The passwords must match";
code = NSValidationStringPatternMatchingError;
isValid = NO;
}
if (outError && errorMessage) {
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : errorMessage };
NSError *error = [[NSError alloc] initWithDomain:kHAB
code:code
userInfo:userInfo];
*outError = error;
}
return isValid;
}
값은 같은 사람 엔티티에 저장되는 가 :
Person *userProfile = [Person MR_createEntity];
NSString *facebookId = @"some id";
[userProfile setFbId:facebookId];
[userProfile setEmail:@"[email protected]"];
[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
그것은 저장 실패 사람이 엔티티가 유효한 암호 유효성 검증을 통과하지 못하고 암호 필드를 확인하지 않는다고 말하는 상황. Facebook에서 가입하는 동안 비밀번호를 입력하거나 비밀번호 입력란을 확인할 필요가 없습니다. "password"및 "confirmPassword"값을 저장하지 않고 컨텍스트를 저장하려면 어떻게해야합니까?
비밀번호 및 confirmPassword 필수 입력란입니까, 아니면 선택 사항입니까? – casademora
두 필드 모두 선택 사항입니다 ... –