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 242605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:51:06+00:00 2026-05-11T20:51:06+00:00

How to perform call back functions in Objective-C? I would just like to see

  • 0

How to perform call back functions in Objective-C?

I would just like to see some completed examples and I should understand it.

  • 1 1 Answer
  • 1 View
  • 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-11T20:51:06+00:00Added an answer on May 11, 2026 at 8:51 pm

    Normally, callbacks in objective C are done with delegates. Here’s an example of a custom delegate implementation;


    Header File:

    @interface MyClass : NSObject {
        id delegate;
    }
    - (void)setDelegate:(id)delegate;
    - (void)doSomething;
    @end
    
    @interface NSObject(MyDelegateMethods)
    - (void)myClassWillDoSomething:(MyClass *)myClass;
    - (void)myClassDidDoSomething:(MyClass *)myClass;
    @end
    

    Implementation (.m) File

    @implementation MyClass
    - (void)setDelegate:(id)aDelegate {
        delegate = aDelegate; /// Not retained
    }
    
    - (void)doSomething {
        [delegate myClassWillDoSomething:self];
        /* DO SOMETHING */
        [delegate myClassDidDoSomething:self];
    }
    @end
    

    That illustrates the general approach. You make a category on NSObject that declares the names of your callback methods. NSObject doesn’t actually implement these methods. This type of category is called an informal protocol, you’re just saying that many objects might implement these methods. They’re a way to forward declare the type signature of the selector.

    Next you have some object be the delegate of “MyClass” and MyClass calls the delegate methods on the delegate as appropriate. If your delegate callbacks are optional, you’ll typically guard them at the dispatch site with something like “if ([delegate respondsToSelector:@selector(myClassWillDoSomething:)) {“. In my example, the delegate is required to implement both methods.

    Instead of an informal protocol, you can also use a formal protocol defined with @protocol. If you do that, you’d change the type of the delegate setter, and instance variable to be “id <MyClassDelegate>” instead of just “id“.

    Also, you’ll notice the delegate is not retained. This is typically done because the object that “owns” instances of “MyClass” is typically also the delegate. If MyClass retained its delegate, then there would be a retain cycle. It’s a good idea in the dealloc method of a class that that has a MyClass instance and is its delegate to clear that delegate reference since it’s a weak back pointer. Otherwise if something is keeping the MyClass instance alive, you’ll have a dangling pointer.

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

Sidebar

Related Questions

I have coded some JavaScript to perform an ajax call in an asp.net application.
I have a map where I'd like to perform a call on every data
I needed to perform a differnt action when an ajax call was completed depending
Will GHC perform tail-call optimization on the following function by default? The only weird
I'm using the Win32 CreateProcess function to perform a call to an external executable.
Is it possible to use a jQuery ajax call to perform Forms Authentication with
I am trying to perform a nested AJAX call using the following code. The
As I understand it, the JQuery load() function retrieves a document and can perform
So I was given this function to read options to perform. I understand the
I want to be able to perform some logic within a callback function based

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.