Objective-C "if" statements not retaining

Posted by seanny94 on Stack Overflow See other posts from Stack Overflow or by seanny94
Published on 2010-04-25T02:44:17Z Indexed on 2010/04/25 2:53 UTC
Read the original article Hit count: 290

Filed under:
|
|
|

I know the title of this question is a bit confusing, but here it goes anyway:

I'm creating an NSString after an if statement but it just doesn't seem to want to retain outside of the statement. My conditional looks like this:

if ([[password stringValue] isEqualToString:@""]) {
    NSString *pwd = [[NSString alloc]initWithString:@"password"];
}
else {
    NSString *pwd = [[NSString alloc]initWithFormat:@"%@", [password stringValue]];
}

... and I call pwd later in the script like this:

NSArray *arguments;
arguments = [NSArray arrayWithObjects: ip, pwd, nil];
[task setArguments: arguments];

But when I do so in this way, the first snippet returns a warning of Unused variable 'pwd' and the latter call ends up in an error of 'pwd' undeclared.

What am I doing wrong here? Thanks in advance. ;)

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa