简体   繁体   English

如何修复 xcode 警告“未使用表达式结果”

[英]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我正在使用我的应用程序进行注册过程,用户输入一个我检查我的数据库的数字。总之长话短说,我将代码传递到我的NSString *startURL有一个我无法摆脱的警告,它说

"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) .你不能只做(@"http://188.162.17.44:8777/ICService/?RegCode=%@",code) Use [NSString stringWithFormat:@"http://188.162.17.44:8777/ICService/?RegCode=%@", tempRegCode] .使用[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.通过编写 (blabla),它变成了一个表达式,您没有将其用作表达式,因此编译器会抱怨。

Change to [NSString stringWithFormat: ...];更改为[NSString stringWithFormat: ...]; and it becomes a method.它变成了一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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