문제

I'm having a problem with respondsToSelector with NSMutableSet.

I have a program like this:

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);
}

I call it using ./program NSMutableSet addObject: str, but the program always says that NSMutableSet doesn't respond to addObject:.

I don't know why respondsToSelector always says that NSMutableSet doesn't respond to addObject. It's the same with ./program NSMutableSet allObjects.

도움이 되었습니까?

해결책

You were checking something completely different...

[NSClassFromString(theClass) init]

needs to be

[[NSClassFromString(theClass) alloc] init]

instead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top