我对respondsToSelector和NSMutableSet有个问题。
我有一个这样的程序:
NSArray *arguments = [[NSProcessInfo processInfo] arguments];
theClass = [arguments objectAtIndex: 1];
theMethod = [arguments objectAtIndex: 2];
theArgument = [arguments objectAtIndex: 3];
id object = [[NSClassFromString(theClass) init] autorelease];
if([object respondsToSelector:NSSelectorFromString(theMethod)]) {
NSLog(@"Result: %@",
[object performSelector:NSSelectorFromString(theMethod) withObject: theArgument]);
} else {
NSLog(@"Class %@ doesn't respond to %@.",
theClass, theMethod);
}我使用./ NSMutableSet addObject: str来命名它,但是程序总是说NSMutableSet不响应addObject:。
我不明白为什么respondsToSelector总是说NSMutableSet不响应addObject。./program NSMutableSet allObjects也是如此。
发布于 2013-06-02 20:55:32
你在检查完全不同的东西..。
[NSClassFromString(theClass) init]需要的是
[[NSClassFromString(theClass) alloc] init]而不是。
https://stackoverflow.com/questions/16887114
复制相似问题