选择器 rac_sendAsynchronousRequest 没有已知的 class 方法

No known class mehtod for selector rac_sendAsynchronousRequest

我知道这听起来很明显,但我收到以下错误:No known class mehtod for selector rac_sendAsynchronousRequest

在一行中:

return [[[NSURLConnection rac_sendAsynchronousRequest]

整个方法 body 是:

+(RACSignal*)download:(NSString*)urlString{

    NSAssert(urlString, @"URL must not be nil");

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];

    return [[[NSURLConnection rac_sendAsynchronousRequest]
              map:^id(RACTuple *value) {

                  return [value second];
              }]

            deliverOn:[RACScheduler mainThreadScheduler]];

}

在我的 header 中,我确实导入了类别和库 headers:

#import<ReactiveCocoa/ReactiveCocoa.h>
#import <ReactiveCocoa/NSURLConnection+RACSupport.h>

NSURLConnection+RACSupport.h中我可以看到方法声明:

@class RACSignal;

@interface NSURLConnection (RACSupport)

// Lazily loads data for the given request in the background.
//
// request - The URL request to load. This must not be nil.
//
// Returns a signal which will begin loading the request upon each subscription,
// then send a `RACTuple` of the received `NSURLResponse` and downloaded
// `NSData`, and complete on a background thread. If any errors occur, the
// returned signal will error out.
+ (RACSignal *)rac_sendAsynchronousRequest:(NSURLRequest *)request;

@end

为什么 XCode 没有看到那个方法?

您的代码中缺少 request 参数:

 return [[[NSURLConnection rac_sendAsynchronousRequest:request]
              map:^id(RACTuple *value) {

                  return [value second];
              }]

            deliverOn:[RACScheduler mainThreadScheduler]];