Where is the code behind this method
Yes all, another newbie question!
I'm doing some maintenance work on an app I inherited and I'm trying to find the code behind this method. In my task.h file I have a optional method, doTask, declared in a protocol, TaskDelegate. In my task.m file I located the method 开发者_Go百科definition for doTask, but it refers back to it's method name so I assumed I'd find another "more complete" method definition in another object. WRONG! I'm obviously missing something very basic here. I haven't been able to find any other references in my code to doTask.
Here's the initial declaration in my header file, task.h
@protocol TaskDelegate<NSObject>
@optional
- (void) doTask;
Here's the method definition in my implementation file, task.m
- (void) doTask
{
if ((self.delegate != nil) && ([self.delegate respondsToSelector:@selector(doTask)]))
{
[self.delegate doTask];
}
}
I assume my method definition is first determining if I have a object delegate already in existence and then seeing if it has a doTask method defined within it; if it does, then it's telling it to execute the doTask method on that delegate. Am I correct?
Well, if so, my question becomes where is the code behind doTask which actually does something? I've really got to be missing something basic here. All help is appreciated! Thanks in advance for your assistance...
As middaparka said, your assumption is spot-on. As for finding the function code for the doTask method, do a Edit -> Find -> Find in Project or command + shift + F and enter 'doTask' (or whatever the function name really is) into the search bar and set it to 'In Project' and it will pull up all instances where the function text shows up, including the function definition.
I assume my method definition is first determining if I have a object delegate already in existence and then seeing if it has a doTask method defined within it; if it does, then it's telling it to execute the doTask method on that delegate. Am I correct?
This is precisely what's happening.
In terms of your "where is the code behind doTask" question - it should be in whatever delegate registers itself with the class in question. (It's a bit confusing in that the same method name is being used but the intent behind the [self.delegate doTask];
line should be clear.)
精彩评论