【发布时间】:2014-02-07 13:59:22
【问题描述】:
我想在 NSURLSession 上创建一个类别。该应用程序编译正常,但是当我尝试调用类别方法时,我得到了
-[__NSCFURLSession doSomething]: unrecognized selector sent to instance 0xbf6b0f0
<unknown>:0: error: -[NSURLSession_UPnPTests testCategory] : -[__NSCFURLSession doSomething]: unrecognized selector sent to instance 0xbf6b0f0
很奇怪,这是我为显示问题而构建的一个测试类。 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
【问题讨论】:
标签: ios categories nsurlsession