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

  • Home
  • SEARCH
  • 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 7197035
In Process

The Archive Base Latest Questions

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

I created a protocol and assigned it to a delegate object @protocol AppBrainDelegate <NSObject>

  • 0

I created a protocol and assigned it to a delegate object

@protocol AppBrainDelegate <NSObject>
@optional
- (void)didLocateUser;
- (void)didFinishLoadingDataWithData:(NSDictionary *)fetchedData;
@end

@interface Brain : NSObject
@property (strong, nonatomic) id <AppBrainDelegate> delegate;

I thought the meaning of this @optional in the protocol declaration means, that controllers don’t have to listen to the delegate method if they don’t want to.

Here’s the crash log if do not implement the first of the delegate methods in the controller. If I do, I don’t crash. Seems like I did not understand the concept of declaring delegate methods as optional. Can you explain to me where my mistake is?

* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[EventViewController didLocateUser]: unrecognized selector sent to instance 0x1fb300’

  • 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-28T20:53:36+00:00Added an answer on May 28, 2026 at 8:53 pm

    The @optional simply suppresses a compiler warning if the method is not implemented in a class that conforms to the protocol. Before calling the delegate method, you still need to check that the delegate implements it:

    if ([delegate respondsToSelector:@selector(didLocateUser)]) {
        [delegate didLocateUser];
    }
    

    Incidentally, you have created your delegate property using strong semantics. Unless you have a particularly good reason to use strong, delegates should be weak, since your Brain class doesn’t own its delegate (if you think about the object graph).

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

Sidebar

Related Questions

I've created a protocol named RecDelegate that's consisted of a method - (void) doSmtng
I have created a sitemap for my site and it complies with the protocol
I am trying to create a delegate protocol for a custom UIView. Here is
I have created a protocol in Clojure 1.2 that handles my own Java classes
I created my OwnCCSprite, and it get the implemented CCStandardTouchDelegate protocol, and ccTouchesBegan event.
I created a protocol and a class to use the protocol. JSTest.h file =
I created a basic TCP server that reads incoming binary data in protocol buffer
I have created the connection to server using Https protocol. Here is my code...
I have created the connection to server using Https protocol. Here is my code...
I created a binary file using a c++ program using protocol buffers. I had

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.