Using NSMethodSignature on iPhone (with Obj-C 2.0 properties)

Using NSMethodSignature on iPhone (with Obj-C 2.0 properties)

Hey guys, I'm running the following code on my phone, where 'object' is a Cat, which is a subclass of Animal. Animal has a property 'color':

NSLog(@"Object: %@", object); NSLog(@"Color: %@", [object color]); NSMethodSignature *signature = [[object class] instanceMethodSignatureForSelector:@selector(color)];  NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; [invocation setTarget:object];  [invocation invoke]; 

The output in my console is:

2009-06-28 16:17:07.766 MyApplication[57869:20b] Object: <Cat: 0xd3f370> 2009-06-28 16:17:08.146 MyApplication[57869:20b] Color: <Color: 0xd3eae0> 

Then, I get the following error:

*** -[Cat <null selector>]: unrecognized selector sent to instance 0xd3f370 

Any clues? I'm using this similar method in other classes, but I can't figure out what I'm doing wrong in this instance. The selector 'color' obviously exists, but I don't know why it isn't being properly recognized.

Javascript for “Add to Home Screen” on iPhone?


What's the best way to communicate between view controllers?
Try any thing like this:. How can I scan barcodes on iOS?
NSLog(@"Object: %@", object); NSLog(@"Color: %@", [object color]);  SEL sel = @selector(color);  NSMethodSignature *signature = [[object class] instanceMethodSignatureForSelector:sel];  NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; invocation.selector = sel; invocation.tarreceive  = object;  [invocation invoke]; 
You were missing a call to NSInvocation's setSelector: method.. __OBJC__ equivalent for Objective-C++ NSMethodSignature records type information for the arguments and return value of a method, although doesn't contain the selector itself. Can autocapitalize be turned off with javascript in mobile safari?So if you want to use it with an NSInvocation you need to set the invocation's selector as well.. “EXC_BAD_ACCESS” error when cell begins scrolling back in view?
Button not removed with removedFromSuperVire

92 out of 100 based on 42 user ratings 1142 reviews