Contribute  :  Calendar  :  Advanced Search  :  Site Statistics  :  Directory  :  Files to download  :  Links for developers  :  Privacy policy  :  Web Resources  :  Polls  
    MacOSX Guru Site Information, tips and tricks, FAQ for Mac OS X developers    
 Welcome to MacOSX Guru Site
 Saturday, March 23 2019 @ 10:21 PM UTC

What's this about SEL and @selector?

Objective-CSEL is the data type for storing a shorthand notation of a method's name. @selector() is a pseudo-function you can use to get a SEL from a method name. Together, they let you do the equivalent of calling a function via a function pointer, but for a method of an object.

Depending on the class of your object, ObjC has to call a different method for the same method name (e.g. NSString's longValue or NSNumber's longValue). To allow that, ObjC uses a SEL to quickly find functions with the same name, which is faster than comparing the actual function name strings. To get such a SEL, you use code like the following:

SEL mySel = @selector(methodNameParam:andParam:);
(for a method declared as -(void)methodNameParam: (int)a andParam: (int)b;) To call a method using a selector, use one of NSObject's performSelector: methods, which pretty much any class inherits from in the end (though maybe indirectly).

What's Related

Story Options

What's this about SEL and @selector? | 0 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
 Copyright © 2019 MacOSX Guru Site
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.06 seconds