简体   繁体   中英

how to fix xcode warning “Expression result unused”

I am doing a registration process with my app where the user enters in a number that I check against my db.. anyway long story short where I pass code into my NSString *startURL have a warning I cannot get rid of, it says

"Expression result unused"

have you ever experienced anything like this and if so how do I fix it?

   -(void)startRegConnect:(NSString *)tempRegCode{

        //tempRegCode = S.checkString;
        NSLog(@"tempRegCode from RegConnection =%@",tempRegCode);


        NSString *code = [[NSString alloc] initWithString:tempRegCode];
        //urlstart string
        NSString *startURL = (@"http://188.162.17.44:8777/ICService/?RegCode=%@",code); //warning here

        NSURL *url = [NSURL URLWithString:startURL];

        //create a request object with that url
        NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];

        //clear out the exisiting connection if there is on
        if (connectionInProgress) {
            [connectionInProgress cancel];
            [connectionInProgress release];
        }

        //Instantiate the object to hold all incoming data
        [cookieData release];
        cookieData = [[NSMutableData alloc]init];

        //create and initiate the connection - non-blocking
        connectionInProgress = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

    }

You can't just do (@"http://188.162.17.44:8777/ICService/?RegCode=%@",code) . Use [NSString stringWithFormat:@"http://188.162.17.44:8777/ICService/?RegCode=%@", tempRegCode] .

It's because of the parenthesis. By writing (blabla) it becomes an expression, which you are not using as an expressing, hence the compiler complains.

Change to [NSString stringWithFormat: ...]; and it becomes a method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM