Not using predicate directly with a bool value.
The code is as follows
@interface Viewcontroller () <UITextFieldDelegate>
@property (Weak, nonatomic) Iboutlet Uiprogressview *levelprogress;
@property (Weak, nonatomic) Iboutlet Uitextfield *pwdtextfield;
@property (Weak, nonatomic) Iboutlet Uitextfield *confirmpwdtextfield;
@property (Weak, nonatomic) Iboutlet UILabel *levellabel;
@end
@implementation Viewcontroller
-(BOOL) Judgewitharray: (Nsarray *) arr withpwd: (NSString *) pwd
{
Nsrange range;
for (int i =0; i<arr.count; i++) {
range = [pwd rangeofstring:arr[i]];
if (range.location! = nsnotfound) {
return YES;
}
}
return NO;
}
-(void) textfielddidendediting: (Uitextfield *) textfield{
[Self.pwdtextfield Becomefirstresponder];
NSLog (@ "%d", self.pwdTextField.isEditing);
nsarray* termArray1 = [[Nsarray alloc] initwithobjects:@ "a", @ "B", @ "C", @ "D", @ "E", @ "F", @ "G", @ "H", @ "I", @ "J", @ "K", @ "L", @ "M", @ "n", @ "O", @ "P", @ "Q", @ "R", @ "s", @ "T", @ "U", @ "V", @ "W", @ "x", @ "Y", @ "Z", Nil];
nsarray* termArray2 = [[Nsarray alloc] initwithobjects:@ "1", @ "2", @ "3", @ "4", @ "5", @ "6", @ "7", @ "8", @ "9", @ "0", nil];
nsarray* termArray3 = [[Nsarray alloc] initwithobjects:@ "A", @ "B", @ "C", @ "D", @ "E", @ "F", @ "G", @ "H", @ "I", @ "J", @ "K", @ "L", @ "M", @ "N", @ "O", @ "P", @ "Q", @ "R", @ "S", @ "T", @ "U", @ "V", @ "W", @ "X", @ "Y", @ "Z", nil];
nsarray* termArray4 = [[Nsarray alloc] initwithobjects:@ "~", @ "", @ "@", @ "#", @ "$", @ "%", @ "^", @ "&", @ "*", @ "(", @ ")", @ "-", @ "_", @ "+", @ "=", @ "{", @ "}", @ "[", @ "]", @ "|", @ ":", @ ";", @ "", @ "", @ "", @ "<", @ ",", @ ", @" > ", @"? ", @"/", @", ", NIL];
NSString *STRRESULT1 = [nsstring stringwithformat:@ '%d ', [Self judgewitharray:termarray1 withpwd: Self.pwdTextField.text]];
NSString *STRRESULT2 = [nsstring stringwithformat:@ '%d ', [Self judgewitharray:termarray2 withpwd: Self.pwdTextField.text]];
NSString *STRRESULT3 = [nsstring stringwithformat:@ '%d ', [Self judgewitharray:termarray3 withpwd: Self.pwdTextField.text]];
NSString *STRRESULT4 = [nsstring stringwithformat:@ '%d ', [Self judgewitharray:termarray4 withpwd: Self.pwdTextField.text]];
Nsmutablearray *arrresult = [[Nsmutablearray alloc]init];
[Arrresult ADDOBJECT:STRRESULT1];
[Arrresult ADDOBJECT:STRRESULT2];
[Arrresult ADDOBJECT:STRRESULT3];
[Arrresult ADDOBJECT:STRRESULT4];
int intresult = 0;
for (int j = 0; j<arrresult.count; j + +) {
if ([Arrresult[j] isequaltostring:@ "1"]) {
Intresult + +;
}
}
if (Intresult <2) {
Self.levelLabel.text = @ "weak";
self.levelProgress.progress = 0.2;
Self.levelProgress.progressTintColor = [Uicolor Redcolor];
}else if (intresult = = 2) {
Self.levelLabel.text = @ "Medium";
Self.levelProgress.progressTintColor = [Uicolor Yellowcolor];
self.levelProgress.progress = 0.6;
}else if (Intresult >2) {
Self.levelProgress.progressTintColor = [Uicolor Greencolor];
self.levelProgress.progress = 0.9;
Self.levelLabel.text = @ "Strong";
}
}
-(void) Viewdidload {
[Super Viewdidload];
Self.pwdTextField.delegate = self;
}
IOS Project Log-Password strength implementation