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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:01:32+00:00 2026-06-12T05:01:32+00:00

I am using a Object method inside the @protocol , but protocol only supports

  • 0

I am using a Object method inside the @protocol , but protocol only supports method declaration , could someone help me about how to connect that with the method definition of the same method .(where to write the method Definition).

  • 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-06-12T05:01:33+00:00Added an answer on June 12, 2026 at 5:01 am

    Protocols are just a list of method declarations without any implementation. They can be used to restrict a set of possible (classes) to those that implement a certain protocol.

    For instance if you had a GasStation class you might want to restrict the type (class) of objects that can be refueled at the station. Of course you could simply require the objects to be a descendant of the class Vehicle, like this:

    @interface GasStation : NSObject
    - (void)refuel:(Vehicle *)vehicle;
    @end
    
    @implementation GasStation 
    - (void)refuel:(Vehicle *)vehicle {
        [vehicle addFuel:100];
    }
    @end
    

    But this wouldn’t allow a jerrycan to be filled up for instance. However allowing any type of object to be passed is a bad idea either, because if you passed an instance of Cat you would certainly get an error when trying to send it an addFuel: message.

    So instead you define a protocol that refuelable classes have to implement:

    @protocol RefuelableThing
    @required
    - (void)addFuel:(float)fuel;
    @end
    

    Now you can use that protocol to restrict what types of objects can be refueled:

    @interface GasStation : NSObject
    - (void)refuel:(NSObject<RefuelableThing> *)thing;
    @end
    

    A Vehicle will of course have a method addFuel: and so can JerryCan implement its own separate version, even though it’s not a Vehicle.

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

Sidebar

Related Questions

the method inside the library I'm using return an object but it's really is
I would like to create an NSInvocation object using a method that takes a
I am using a method that returns an Object when called. That object's type
I'm trying to add a toBool() method inside the Object object using prototype... something
When using log4j, the Logger.log(Priority p, Object message) method is available and can be
I'm using the socket.makefile method to create a file-like object on a UDP socket
I am trying to apply a method to an existing object which involves using
We're stuck with using buffers on the SocketAsyncEventArgs object. With the old socket method
I am new to using soap. I have a soap method returning an object.
How do I invoke a method (e.g. setter inside object class) on an already

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.