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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:29:05+00:00 2026-05-23T18:29:05+00:00

I want to programmatically associate code with selectors. I am not clear on how

  • 0

I want to programmatically associate code with selectors. I am not clear on how to do that in Objective C. In Ruby, I might override method_missing. In Common Lisp, I might define a macro. In Objective C, I can get part of the way there with @dynamic properties, but I’m unclear on how to actually implement them.

Here’s a concrete example: I want to use an NSMutableDictionary to persistently store parts of my object. My class has two methods that handle the basic functionality, and a bunch of dynamic properties (matching @propertys exist in @interface):

@dynamic name;
@dynamic age;
@dynamic favoriteColor;
- (id)accessor:(NSString*)name {
    return [[self dict] objectForKey:name];
}
- (void)mutator:(NSString*)name value:(id)value{
    [[self dict] setObject:value forKey:name];
    [[self dict] writeToFile:[self filename] atomically:YES];
}

Now I am looking for a way to translate a call like

[myInstance setName:@"iter"];

into

[self mutator:@"name" value@"iter"];

I wonder if there is an idiomatic way to do that in ObjC.

  • 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-23T18:29:05+00:00Added an answer on May 23, 2026 at 6:29 pm

    This isn’t really an idiomatic thing to do in Objective-C, and there’s certainly nothing like a Lisp macro available. NSObject and the runtime do, however, provide three possible points for you to intercept and handle messages referring to methods that don’t otherwise exist. In the order they are used by the runtime: resolveInstanceMethod:, forwardInvocation: and doesNotRespondToSelector:. The documentation for each of them explains their use and gives some examples.

    The first requires you to actually write out and add a method to the class, which doesn’t seem like it will achieve the dynamic state of affairs you desire. The last by default raises an exception and doesn’t provide for any return value. Almost certainly, forwardInvocation is what you want to look into. It allows your object to ask another object to handle a method call, including the passed arguments; it should be possible for you to make your object handle the call itself in a way that at least gets you close to what you’re going for.

    Also, the “Message Forwarding” chapter of the Runtime Programming Guide gives some examples of tasks similar to your requirement.

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

Sidebar

Related Questions

I want to programmatically close a window using Ruby on Mac OS X (i.e.
I want to programmatically get the servlet containers port that my Java EE application
I want to programmatically select the network card that is connected to the Internet.
I want to programmatically create a new column in an MS Access table. I've
I want to programmatically verify the status of an application to see if it
I want to programmatically invoke an event handler for a control. For example: DateTimePicker
I want to programmatically create a new log4j ConsoleAppender and add it as an
I want to programmatically read the contents of the /etc directory. If possible please
I want to programmatically create a directory on the server using ASP.NET. I have
I want to programmatically change formulas in a whole lot of reports, like in

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.