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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:14:55+00:00 2026-05-26T20:14:55+00:00

On iOS4, if I have a non-public protocol like: @protocol HTTPDelegate <NSObject> @optional –

  • 0

On iOS4, if I have a non-public protocol like:

@protocol HTTPDelegate <NSObject>
@optional
- (void) methodDidFinish:(NSDictionary *) response;
- (void) methodDidFail:(NSString *) error;
@end

And I have a pointer to a delegate like:

id<HTTPDelegate> delegate;

Then, I want to optionally call that delegate method:

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

That works great. However, I later decide to use an NSError* for the error and change the protocol to:

@protocol HTTPDelegate <NSObject>
@optional
- (void) methodDidFinish:(NSDictionary *) response;
- (void) methodDidFail:(NSError *) error;
@end

If I just change the type of one parameter in an optional protocol method, the compiler won’t complain when I check (with respondsToSelector:) if the delegate implements that method and it will let me pass errorString with the methodDidFail: message. Instead, later, at runtime, this will result in an invalid selector crash.

What if I want the compiler to complain and check the types of the parameters? Is there a way to do that?

  • 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-26T20:14:55+00:00Added an answer on May 26, 2026 at 8:14 pm

    No there is no way to do check the parameter types. Better you add a new method when you change the types. I’d name the delegate methods like so:

    - (void) methodDidFailWithError:(NSError *) error;
    
    - (void) methodDidFailWithString:(NSString *) errorString;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have iOS4 specific code (ie the MKMapView overlays) in an
I have an app that works well on iOS4. I want to add new
I have a hard time to understand my iPhone Application strange behavior in iOS4.
I have spotted an example in book: iOS4 Programming Cookbook that I can't understand:
I have an iOS (4.0) app that I would like to change the alpha
I have upgraded my iPad to iOS4.2 (gold master 8C134) but I didn't upgrade
I have an UIView with many UIImageViews as subviews. The app runs on iOS4
Is it possible to have an App (running iOS4 on hardware supporting multi-tasking) which
I'm developing an iPhone iOS4 application and one of the things that it have
I have a project on iPhone with iOS4. A instance variable of app delegate

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.