Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7181637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:35:58+00:00 2026-05-28T17:35:58+00:00

I’m only really beginning IOS development but have a few years dev of ASP.net

  • 0

I’m only really beginning IOS development but have a few years dev of ASP.net through C#. To be honest I’ve never had a real need to understand delegates / events etc. before, I know that I’m using them when programming web.forms but a lot of the functionality is taken care of by the framework, behind the scenes.

So now that I’m developing in IOS I’m forced to try to understand how they function (I’m presuming here that the theory of delegates / events is the same across languages, maybe I’m wrong). Anyway, the following line of code in IOS:

 if ([self.delegate respondsToSelector:@selector(startImporting:)])
 {
            [self.delegate startImporting:self];
 }

Am I right in thinking that, in pseudo code, it means something along the lines of:

If the method/class calling this method has a method in it called ‘startImporting’ then call the method ‘startImporting’ within the calling class.

Hope that’s clear. If that’s the case then would it essentially be the same as having a static method in C# that you could call with something like:

myImportClass.startImporting();

Presumably not, or that’s how it would be done. So, am I missing the whole point of delegates, their benefits etc? I’ve read what they are over and over and while it makes sense, it never clicks, I never (in web forms anyway) have really seen the benefit of using them.

This becomes increasingly important as I’m moving to using lambda expressions in .net and they’re closely linked to delegates in C# so while I can just start using them, I’d prefer to know why and what benefit delegates actually are.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:35:59+00:00Added an answer on May 28, 2026 at 5:35 pm

    The delegation pattern in Cocoa is used to inform (report progress, etc.) or query (ask for credentials, etc.) another object without knowing much about it.

    Typically, you use a protocol to define what methods you will call on the delegate and the delegate then needs to conform to that protocol. You can also add methods that the delegate doesn’t need to implement (optional). When you do so, you’ll have to call -respondsToSelector:, because you don’t know whether the delegate wants the particular method to be called or not.

    An example:
    You have a class that produces something, let’s call it Machine and a worker of the class Worker. The machine needs to be adjusted for the task:

    Machine *machine = [[Machine alloc] init];
    [machine prepareWithParameters:myParameters];
    

    Now that we have the machine we want to produce a massive amount of Stuff:

    [machine produceStuff];
    

    Okay, we’re done. But how do we know when an unit of Stuff has been produced? We could have our worker constantly standing beside our machine and wait:

    while (![machine isFinished]) {
        if ([machine didProduceStuff]) {
            Stuff *stuff = [machine producedStuff];
            [self doSomethingWithStuff:stuff];
        }
        else {
            // Get a very large coffee...
        }
    }
    

    Wouldn’t it be great if the machine did inform us automatically, when it’s done with producing an unit of Stuff?

    @protocol MachineDelegate <NSObject>
    @optional
        - (void) machine:(Machine *)machine didProduceStuff:(Stuff *)stuff;
    @end
    

    Let’s add the worker as a delegate of machine:

    Worker *worker;
    Machine *machine = [[Machine alloc] init];
    [machine prepareWithParameters:myParameters];
    [machine setDelegate:worker]; // worker does conform to <MachineDelegate>
    
    [machine produceStuff];
    

    When Machine is done producing something, it will then call:

    if ([[self delegate] respondsToSelector:@selector(machine:didProduceStuff:)])
        [[self delegate] machine:self didProduceStuff:stuff];
    

    The worker will then receive this method and can do something:

    - (void) machine:(Machine *)machine didProduceStuff:(Stuff *)stuff {
        [self doSomethingWithStuff:stuff];
        if ([machine isFinished])
            [self shutDownMachine:machine];
    

    }

    Isn’t that much more efficient and easier for the worker? Now he can do something more productive than standing besides the machine while the machine is still producing. You could now add even more methods to MachineDelegate:

    @protocol MachineDelegate <NSObject>
    @required
        - (void) machineNeedsMaintenance:(Machine *)machine;
        - (void) machine:(Machine *)machine fatalErrorOccured:(Error *)error;
        - (BOOL) machine:(Machine *)machine shouldContinueAfterProductionError:(Error *)error;
    @optional
        - (void) machineDidEnterEcoMode:(Machine *)machine;
        - (void) machine:(Machine *)machine didProduceStuff:(Stuff *)stuff;
    @end
    

    Delegates can also be used to change the behavior of an object without subclassing it:

    @protocol MachineDelegate <NSObject>
    @required
        - (Color *) colorForStuffBeingProducedInMachine:(Machine *)machine;
        - (BOOL) machineShouldGiftWrapStuffWhenDone:(Machine *)machine;
    @end
    

    I hope I could help you understand the benefit of abstracting your code using delegates a little bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.