performSelector:withObject fails with class object
performSelector:withObject fails with class object
- Subject: performSelector:withObject fails with class object
- From: Tron Thomas <email@hidden>
- Date: Thu, 05 Feb 2009 21:50:43 -0800
I have a couple of classes that are delcared like this:
#import <objc/objc.h>
#import <objc/Object.h>
@interface SomeClass : Object
{
@private
// Instance data members ...
}
+ (SomeClass*)instanceFromData:(id)data;
// Other methods ...
@end
@interface SomeOtherClass : Object
{
@private
// Instance data members ...
}
+ (SomeOtherClass*)instanceFromData:(id)data;
// Other methods ...
@end
In yet another class, I have this function:
+ (id)createInstanceForClass:
(const char*)className
withData:(id)data
{
id metaClass = ::objc_getMetaClass(className);
if(nil == metaClass){
return nil;
}
unsigned int count;
Method* method = ::class_copyMethodList(metaClass, &count);
for(unsigned int index = 0; index < count; ++index){
std::clog << ::sel_getName(::method_getName(method[index])) <<
std::endl;
}
return [metaClass performSelector:@selector(instanceFromData:)
withObject:data];
}
When the middle section of the function containing the
class_copyMethodList is simply meant for verification, and prints:
instanceFromData
when the class name for either of the first two classes is provided.
This seems to indicate the proper class object is being used and the
expectation is that the call to performSelector:withObject: should
succeed.
However, when the performSelector:withObject: is executed, output like
the following is logged, and the program traps in the debugger:
*** NSInvocation: warning: object 0x1b0dc of class 'Object' does not
implement methodSignatureForSelector: -- trouble ahead
*** NSInvocation: warning: object 0x1b0dc of class 'Object' does not
implement doesNotRecognizeSelector: -- abort
What is needed to make this code work as expected?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden