tacos_tacos_tacos
tacos_tacos_tacos

Reputation: 10585

Is there a way of specifying a selector without the @selector syntax / what is going on behind the scenes with @selector

Is @selector a convenience syntax for some sort of longer C syntax, or is it a "hard wired" part of the Objective-C language/compiler? For example, I know that when I call @property, depending on the arguments, different equivalent Objective-C code is "generated" re: getters and setters. What is going on behind the scenes with @selector? Is it specifying an Objective-C message?

Upvotes: 0

Views: 197

Answers (2)

yuji
yuji

Reputation: 16725

To answer the question in your title, NSSelectorFromString will let you create a selector from an NSString (you can also do the opposite with NSStringFromSelector), although it's more efficient to use @selector.

Upvotes: 2

Rob Napier
Rob Napier

Reputation: 299673

@selector() is a part of the language. It specifies literal SEL just like @"" specifies a literal NSString.

It's worth understanding that @selector represents a selector, not a message. A selector is just a name. It's just one small part of a message. It doesn't even carry type information.

Also note that @property doesn't generate anything. It just promises that the object will respond to one or two selectors (the getter and the setter). There are several ways to fulfill that contract. @synthesize is just one of them. You can also manually implement the needed methods, or use @dynamic to promise that it will somehow be handled at runtime.

Upvotes: 3

Related Questions