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?
Is @selector a convenience syntax for some sort of longer C syntax, or is
Share
@selector()is a part of the language. It specifies literalSELjust like@""specifies a literalNSString.It’s worth understanding that
@selectorrepresents 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
@propertydoesn’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.@synthesizeis just one of them. You can also manually implement the needed methods, or use@dynamicto promise that it will somehow be handled at runtime.