2013-01-10 21 views
-1

我試圖做一個簡單的HTTP請求的方法,但作曲時,我得到這個錯誤:Objective-C的獲得:錯誤:Objective-C的方法有望選擇

Compiling file main.m ... 
In file included from main.m:1: 
./HttpManager.h:4:2: error: expected selector for Objective-C method 
-<NSURL*> getUrlContent:(NSString) url; 
~^ 
main.m:11:17: warning: instance method '-getUrlContent:' not found (return type defaults to 'id') 
     NSURL *myURL = [pHttpManager getUrlContent:@"http://www.cnn.com"]; 

我簡單的源代碼:

HttpManager.h

#import <Foundation/Foundation.h> 

@interface HttpManager:NSObject 
-<NSURL*> getUrlContent:(NSString) url; 
@end 

HttpManager.m

#import "HttpManager.h" 

@implementation HttpManager 


-<NSURL*> getUrlContent:(NSString) url 
{ 
    NSURL *myURL = [NSURL URLWithString:url]; 
    return myURL; 
} 
#end 

的main.m

#import "HttpManager.h" 
#import <Foundation/Foundation.h> 
int main(int argc,char** argv) 
{ 

    HttpManager* pHttpManager; 
    pHttpManager = [[HttpManager alloc] init]; 
    NSURL *myURL = [pHttpManager getUrlContent:@"http://www.example_site.com"]; 
    NSString *myHomePage = [NSString stringWithContentsOfURL: myURL 
          encoding: NSASCIIStringEncoding error: NULL]; 

    NSLog(@"%@", myHomePage); 

    return 0; 
} 

我在做什麼錯在這裏?

回答

1

試試這個

-(NSURL*) getUrlContent:(NSString*) url 
{ 
NSURL *myURL = [NSURL URLWithString:url]; 
return myURL; 
} 

而且我們是U使用<>而不是()?也取代他們。