我想在NSURLSession上创建一个类别.该应用程序编译好,但当我尝试调用我得到的类别方法
-[__NSCFURLSession doSomething]: unrecognized selector sent to instance 0xbf6b0f0
<unknown>:0: error: -[NSURLSession_UPnPTests testCategory] : -[__NSCFURLSession doSomething]: unrecognized selector sent to instance 0xbf6b0f0
Run Code Online (Sandbox Code Playgroud)
很奇怪,这是我为了显示问题而构建的测试类.NSString上的类别工作正常,但NSURLSession上的类别无法在运行时找到该方法.我怀疑这是内部的东西.
意见请:-)
#import <XCTest/XCTest.h>
@interface NSString (test)
-(void) doSomethingHere;
@end
@implementation NSString (test)
-(void) doSomethingHere {
NSLog(@"Hello string");
}
@end
@interface NSURLSession (test)
-(void) doSomething;
@end
@implementation NSURLSession (test)
-(void) doSomething {
NSLog(@"Hello!!!!");
}
@end
@interface NSURLSession_UPnPTests : XCTestCase
@end
@implementation NSURLSession_UPnPTests
-(void) testCategory {
[@"abc" doSomethingHere];
NSURLSession *session = [NSURLSession sharedSession];
[session doSomething];
}
@end
Run Code Online (Sandbox Code Playgroud)