2013-01-10 19 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使用<>而不是()?也取代他们。