Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am making a server call in some Objective-c code. If it returns as a @"yes", it will do an action. For some reason, the // DO ACTION HERE part is never reached.

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSString *returnStringResults = returnString;
NSString *yesText = @"yes";

if (returnStringResults == yesText) {
    testLabel.text = @"Success";
    // DO ACTION HERE
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
483 views
Welcome To Ask or Share your Answers For Others

1 Answer

if ([returnStringResults isEqualToString:yesText]) {
    testLabel.text = @"Success";
    // DO ACTION HERE
}

Edit: As bbum pointed out, NSString *returnStringResults = returnString; does nothing.

So really, remove that line and use

if ([returnString isEqualToString:yesText]) {
    testLabel.text = @"Success";
    // DO ACTION HERE
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...