objective-c - 没有选择器的类方法…即使Xcode可以识别该方法

标签 objective-c debugging compiler-errors selector class-method

我有3个文件:main.m,CGOAuth.h,CGOAuth.m(取自https://github.com/guicocoa/cocoa-oauth)

在main.m中,我调用(在main方法中):

 [GCOAuth URLRequestForPath:@"websites" 
  HTTPMethod:@"GET" 
  parameters:nil scheme:@"https" 
  host:@"blah"           
  consumerKey:CONSUMER_KEY 
  consumerSecret:CONSUMER_SECRET 
  accessToken:accessToken 
  tokenSecret:tokenSecret];

我得到的错误是,它说选择器URLRequestforPath ...没有类方法。

在我导入到main.m中的GCOAuth.h中,是以下声明:
 + (NSURLRequest *)URLRequestForPath:(NSString *)path
                     HTTPMethod:(NSString *)HTTPMethod
                     parameters:(NSDictionary *)parameters
                         scheme:(NSString *)scheme
                           host:(NSString *)host
                    consumerKey:(NSString *)consumerKey
                 consumerSecret:(NSString *)consumerSecret
                    accessToken:(NSString *)accessToken
                    tokenSecret:(NSString *)tokenSecret;

实现在GCOAuth.m中。

我尝试这样做:
[[GCOAuth alloc] URLRequestForPath:@"websites" 
  HTTPMethod:@"GET" 
  parameters:nil scheme:@"https" 
  host:@"blah"           
  consumerKey:CONSUMER_KEY 
  consumerSecret:CONSUMER_SECRET 
  accessToken:accessToken 
  tokenSecret:tokenSecret];

但是我只是得到错误:没有可见的@interface声明选择器URLRequestForPath ...。

我看不到我在做什么错。如果没有用于选择器的类方法,为什么Xcode的自动补全功能可以让我使用该方法?

编辑(这是CGOAuth.m的实现):
 + (NSURLRequest *)URLRequestForPath:(NSString *)path
                     HTTPMethod:(NSString *)HTTPMethod
                     parameters:(NSDictionary *)parameters
                         scheme:(NSString *)scheme
                           host:(NSString *)host
                    consumerKey:(NSString *)consumerKey
                 consumerSecret:(NSString *)consumerSecret
                    accessToken:(NSString *)accessToken
                    tokenSecret:(NSString *)tokenSecret {
// check parameters
if (host == nil || path == nil) { return nil; }

// create object
GCOAuth *oauth = [[GCOAuth alloc] initWithConsumerKey:consumerKey
                                       consumerSecret:consumerSecret
                                          accessToken:accessToken
                                          tokenSecret:tokenSecret];
oauth.HTTPMethod = HTTPMethod;
oauth.requestParameters = parameters;

NSString *encodedPath = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *URLString = [NSString stringWithFormat:@"%@://%@%@", scheme, host, encodedPath];
if ([[HTTPMethod uppercaseString] isEqualToString:@"GET"]) {
    // Handle GET
    if ([oauth.requestParameters count]) {
        NSString *query = [GCOAuth queryStringFromParameters:oauth.requestParameters];
        URLString = [NSString stringWithFormat:@"%@?%@", URLString, query];
    }
}
oauth.URL = [NSURL URLWithString:URLString];

NSMutableURLRequest *request = [oauth request];
if (![[HTTPMethod uppercaseString] isEqualToString:@"GET"] && [oauth.requestParameters count]) {
    // Add the parameters to the request body for non GET requests
    NSString *query = [GCOAuth queryStringFromParameters:oauth.requestParameters];
    NSData *data = [query dataUsingEncoding:NSUTF8StringEncoding];
    NSString *length = [NSString stringWithFormat:@"%lu", (unsigned long)[data length]];
    [request setHTTPBody:data];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setValue:length forHTTPHeaderField:@"Content-Length"];
}

// return
return request;

}

这是我尝试过但仍无法正常工作的一些事情,重新启动Xcode并进行清理。

我知道Xcode可以识别该方法,因为(a)代码完成为我提供了上述方法的名称,并且(b)它出现在侧边栏(左侧)的层次结构 View 中。
时间就是生命!

最佳答案

您是否在主类中导入了CGOAuth.h?检查项目构建阶段是否存在CGOAuth类。

关于objective-c - 没有选择器的类方法…即使Xcode可以识别该方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17096715/

相关文章:

python - 莎士比亚编程语言帮助 - Windows

ios - UICollectionView 选定的单元格索引始终为零

iPhone 多 View 旋转 hell

asp.net - 在 Web 项目中托管时调试 Silverlight?

c++ - 我在哪里可以看到 mfc 应用程序中的 printf 输出?

c++ - 如何分离调试和 Release模式代码

c++ - 奇怪的重新定义的符号

c++ - 如何检查一个类是否具有特定功能以避免编译时问题?

ios - 嵌入自定义容器 View Controller 时,内容位于导航栏下方。

IOS,为什么有些开发人员在模拟中创建带下划线的变量(_variable)