Tuesday, November 27, 2012
selector objective C
Selector is another feature which supports ObjectiveC. A Selector is same as function pointers in C. So Using selector, we will get the reference of the method, later we will use that reference for calling the method. A SEL is a special type which holds a pointer to the symbolic name of a method.
@selector is a directive to get the pointer for the method. After getting the reference, using below two methods we can do the operations.
@selector is a directive to get the pointer for the method. After getting the reference, using below two methods we can do the operations.
- respondsToSelector : This used to check whether the method definition is available or not. It does not look for the declaration of the method, it just checks in implementation file for the method definition.
- performSelector : This is used to call the method.
//both are same , any one is fine SEL selectorName= @selector(methodName); SEL selectorName = NSSelectorFromString(@”methodName");Using Selectors to Call Methods: Below is the example for the usage of the selector and its methods.
//This is in .h file @interface selectorDemo : NSObject -(void) display; -(void) output; @end //below is in .m file @implementation selectorDemo -(void) display { NSLog(@"this is display function"); } -(void) output { NSLog(@"this is output function"); } @end //this is in main.m int main(int argc, const char * argv[]) { selectorDemo *obj = [[selectorDemo alloc] init]; // This selector declaration for display method SEL selDisplay = @selector(display); //checking whether method definition is available or not if([obj respondsToSelector:selDisplay]) { //calling method [obj performSelector:selDisplay]; } //another syntax for the selector declaration SEL selOutput = NSSelectorFromString(@"output"); //calling method [obj performSelector:selOutput]; return 0; }
Subscribe to:
Post Comments (Atom)
Popular Posts
-
A universally unique identifier ( UUID ) is an identifier standard used in software construction, standardized by the Open...
-
Recently I started working on Japser Studio professional for my new project Cloud to generate the reports. I was very new to all cloud ...
-
Below is C program for AVL Tree implementation. #include<stdio.h> #include<malloc.h> typedef struct bst { int info; int hei...
-
strcmp is another string library function which is used to compare two strings and returns zero if both strings are same , returns +ve valu...
-
One of the complex operation on binary search tree is deleting a node. Insertion is easy by calling recursive insertion. But deletion wont...
-
We have recently faced one tricky issue in AWS cloud while loading S3 file into Redshift using python. It took almost whole day to inde...
-
Object slicing: when a derived class object is assigned to a base class object. only base class data will be copied from derived class and...
-
We have faced lot of weird issues while loading S3 bucke t files into redshift. I will try to explain all issues what we faced. Before go...
-
Below code is to find the cube root of a given integer number with out using pow math library function. Its very simple and brute force...
-
Recently we faced one issue in reading messages from SQS in AWS cloud where we are processing same message multiple times. This issue we...
No comments:
Post a Comment