Objective-C获取:错误:Objective-C方法的预期选择器

时间:2013-01-10 08:42:05

标签: objective-c

我正在尝试制作一个简单的http请求方法但是在编译时我收到了这个错误:

 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 个答案:

答案 0 :(得分:1)

试试这个

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

我们正在使用&lt;&gt;代替 ()?也替换它们。