Reputation: 1
Hi I am trying to implement Captcha functionality. The following code, i have used for generating random word:
-(void) createCaptchaWord{
lettersArray = [[NSMutableArray 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];
randomWord = @"";
for(NSUInteger i=0;i<5;i++){
NSUInteger randomNumber = arc4random()%[lettersArray count];
randomWord = [randomWord stringByAppendingString:[lettersArray objectAtIndex:randomNumber]];
//randomWord = [NSString stringWithFormat:@"%@%@",randomWord,[lettersArray objectAtIndex:randomNumber]];
}
NSString *captchaUrl = [NSString stringWithFormat:@"%@%@",CommonFunctions.captchaImgUrl,randomWord];
UIImage *captchaImage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:captchaUrl]]];
[captchaImgView setImage:captchaImage];
}
The problem is with the variable randomWord. I can access this variable inside the method named "createCaptchaWord". There is another function to save all the information entered. In that method, when i tried to access the variable "randomWord", I got the exception EXC_BAD_ACCESS. Then i enabled NSZombie. Thus i got the following message in the console:
-[CFString respondsToSelector:]: message sent to deallocated instance 0x4656c10
Can anyone help me to solve this issue.
Regards, Sreelash
Upvotes: 0
Views: 98
Reputation: 1617
You have to retain the value which will be assigned to the randomWord
variable with either using retain
or a setter method (when it's a property) like self.randomWord = ...
Upvotes: 1