_cmd unrecognized by compiler?

Am working on some code that needs to basically do this:


NSLog(@"%@", NSStringFromSelector(_cmd))


but it seems that no matter what I do, Xcode wants to replace "_cmd" with "rcmd" because it does not recognize "_cmd".


Unless the structure of ObjC has dramatically changed, "self" and "_cmd" are invisible paramters to every method which is really nothing more than a C call at it's fundamental structure. In otherwords, "_cmd" is like the "air" that Objective C breaths... gotta be there... How can this not work?

So what am I doing wrong? If I take this out and put in @"Foo Foo Kitty" everyting compiles and runs.


Since the image posting here does not seem to work in the latest Safari, here is the error:

(use of undeclared identifier "_cmd"; did you mean "rcmd"?)

https://www.evernote.com/l/ACBl0fglWetDzogNMr29p1QE1ivEEZSj4u8B/image.png


Ref:

Objective C Messaging - how it works

http://apple.co/1dO4VP4


Mar 2015 Apple Sample Code with _cmd

http://apple.co/1dO5bOf

Accepted Reply

Is that code in fact in a method body? Show the surrounding context.

Replies

Is that code in fact in a method body? Show the surrounding context.

self refers to the current class/controller. _cmd is the autosynthesized property you declared

in the header for this class. You can't just pick something out of thin air and expect it to do

what you expect.

Not really, _cmd is not an autosynthesized property but a parameter that objective-c/compiler add to every method. Just like 'self'.


@cerniuk : Mind sharing more details of the method? Is this an objective-c method, c method etc?

Just a little follow up. I am wrestling with some code generated by a SOAP code generator. The NSLog statement was indeed inside of a very long C function vs part of a method in the class. The author of the system seems to love generating and using proc pointers from within his own methods. Seems to overcomplicate the output. Regardless, Ken, your questsion was the answer... it was not inside of a method hence no invisible parameter to leverage.