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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:59:41+00:00 2026-05-25T11:59:41+00:00

In objective-c it is possible to add a @dynamic to a property. Is this

  • 0

In objective-c it is possible to add a @dynamic to a property.

Is this also possible for normal instance methods?

EDIT
I think i wasn’t clear enough.

I want to do the following:

@interface MyClass
@property (retain) NSObject *somePropertyObject;
- (void) myMethod;
@end

@implementation MyClass

@dynamic somePropertyObject;

//Make myMethod dynamic. I do not want to implement it. Like C++ Virtual

@end
  • 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-25T11:59:42+00:00Added an answer on May 25, 2026 at 11:59 am

    I think you might be asking how to declare a method that will be implemented some time later somewhere else.

    The Objective-C way to do that is to use Protocols.

    You declare a protocol like this, usually in a header file

    @protocol MyProtocol <NSObject> {
    @optional
        - (void)optionalMethod;
    @required
        - (void)requiredMethod;
    }
    @end
    

    This declares two methods, one which is optional and one is required. To use this protocol you declare the conformance when declaring the class that will implement the protocol

    @interface MyConformingClass : NSObject <MyProtocol> {
    }
    // you don't have to redeclare methods that are declared in the protocol
    @end
    

    This new class is checked at compile time for the implementation of requiredMethod so it has to implement it, but it can choose whether or not to implement the optionalMethod

    Now, any class that requires instances of objects to conform to the protocol can declare this, for example, in the interface

    @interface RequiringClass : NSObject {
        MyConformingClass <MyProtocol> *conformingClassObject;
    }
    …
    @end
    

    Again, this is checked at compile time

    To make sure that the conforming class implement the @optional methods, we can use this handy structure

    if [conformingClassObject respondsToSelector:@selector(optionalMethod)] {
        [conformingClassObject optionalMethod];
    } else {
        // Do something here because the optional method isn't provided
    }
    

    Examples of this are all over Cocoa – it’s a class can provide a list of actions that it would like to farm out to it’s delegate, the delegate adopts the protocol and provides the implementations of those delegate methods. The calling object can then check if this delegate responds to those methods at runtime as I’ve described above, and call those methods to perform actions, or provide information where ever it needs to.

    This is used quite a lot in Objective-C, where classes provide a list of methods that they would like some other class to perform, unlike virtual functions, where a class declares functions it wants subclasses to provide implementations for. Particularly as Composition is favoured over inheritance in the language. Rather than create a subclass to provide an implementation, you just create another class that can do the same thing, and add a reference to that in the class instead.

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

Sidebar

Related Questions

Objective-C has directives like: @interface @implementation @end @protocol @property @synthesize I think of these
Is it possible to add properties to an Objective C object at runtime?
Possible Duplicate: Calling Python from Objective-C I'm a long-time Python programmer and short-time Cocoa
Is it possible to use the __unused attribute macro on Objective-C object method parameters?
I'm fairly new to Objective-C and wondering if it's possible to type objects as
Possible Duplicate: How do I concatenate strings in Objective-C? I have two strings and
Is it possible to forward a request, passing along all GET/POST params? I think
I'm working with Objective-C and I need to add int's from a NSArray to
Possible Duplicate: Objective C: what is a “(id) sender”? What is the (id)sender for
Possible Duplicate: How to add percent sign to NSString I am trying to print

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.