2011-07-14 45 views
4

我做我的應用程序的註冊過程,其中用戶在一個數字,我覈對我的分貝進入..反正長話短說,我通過代碼到我的NSString * startURL有一個警告,我無法擺脫的,它說如何解決Xcode的警告「表達式結果未使用」

「表達式結果未使用」

你有沒有經歷過這樣的事,如果讓我怎麼解決?

-(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]; 

    } 
+0

這不是你的問題的答案,但你爲什麼要分配一個新的字符串('code'),然後爲它指定tempRegCode的值?你可以毫無問題地使用tempRegCode。 – sosborn

+0

我只是這樣做,認爲它可以解決這個問題,因爲我不知道爲什麼會發生問題,我認爲這可能是奇怪的,因爲我改變了我的代碼,而沒有將傳入的字符串傳遞給另一個字符串。 –

+0

公平 - 我們都有過這些時刻:) – sosborn

回答

12

您不能只是做(@"http://188.162.17.44:8777/ICService/?RegCode=%@",code)。使用[NSString stringWithFormat:@"http://188.162.17.44:8777/ICService/?RegCode=%@", tempRegCode]

+0

謝謝,我知道這是...有一個赫克有我的頭去了幾天!大聲笑感謝指出明顯! –

2

這是因爲括號。通過編寫(blabla)它變成了一個表達式,你並沒有將它用作表達式,因此編譯器會抱怨。

更改爲[NSString stringWithFormat: ...];,它成爲一種方法。

相關問題