views:

53

answers:

2

Hey all, this should be a simple task but for some reason i am making it harder... I am trying to save some text from an XML file to a NSString. But when i debug it, the string says "Out of scope".

Here is my code:

in my .h file:

 @interface RootViewController : UIViewController<MBProgressHUDDelegate> {
     NSString *thePW;   
 }

and my .m file:

 NSString *thePW;
 ...
 - (void)viewDidLoad {
 ...
    if(e == nil){
        NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

        thePW = response; // <-- this is where it has "Out of scope"
        [response release];
    }
 }

 - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
 {
     if (buttonIndex != [alertView cancelButtonIndex])
     {
        if (thePW == @"0000")
        {
           NSLog(@"correct!");
        }
     }
 }
A: 

Drop the redeclaration of thePW in your .m file

Also, if you want to keep the value of response in thePW be sure to retain it as well.

TomH
Took out the redeclaring in the .m file but it still has the "Out of Scope" on it when i check it in the IF()...I also tried to retain it using this: @property (nonatomic,retain) NSString *thePW; but i still get the same "Out of Scope".
StealthRT
If you made it a property, assign it with `self.thePW = response;` so the setter method is called.
drawnonward
drawnonward: doing that it gives me the error of "*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[RootViewController thePW]: unrecognized selector sent to instance 0x3b04880'"
StealthRT
A: 

You may also try:

thePW = [NSString stringWithFormat:@"%@",response];   // to assign the string value.

and while comparing strings:

(thePW isEqualToString @"0000")
neha