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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:56:43+00:00 2026-05-31T15:56:43+00:00

Consider an object chain like: foo.bar.baz.bing In this particular instance, I am given foo

  • 0

Consider an object chain like:

foo.bar.baz.bing

In this particular instance, I am given foo and I wish to evaluate the method bing. In code I would do the following:

[[[foo bar] baz] bing];

Or, if bing were a property, I could evaluate it thusly:

id result = foo.bar.baz.bing;

Now consider the situation where I am given foo and then bar.baz.bing in the form of an NSString object. I came up with the following method to evaluate down to bing, but I am wondering if there is a simpler way to do this.

- (id)evaluator:(id)parentObject withChain:(NSString *)objectChain
{
    id currentObject = parentObject;

    for (NSString *component in [objectChain componentsSeparatedByString:@"."])
    {

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        currentObject = [currentObject performSelector:NSSelectorFromString(component)];
#pragma clang diagnostic pop
    }
    return currentObject;
}

Note: The above code example was contrived to demonstrate the point. I am aware of the dangers of calling init, alloc, copy, mutableCopy, or new using a method like this. The actual use in code is very carefully managed to avoid any situations where ARC would require a release.

  • 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-31T15:56:44+00:00Added an answer on May 31, 2026 at 3:56 pm

    Use Key-Value Coding.

    [parentObject valueForKeyPath:objectChain];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider: var object = { foo: {}, bar: {}, baz: {} } How would
Consider this class: class foo(object): pass The default string representation looks something like this:
Consider an object declared in a method: public void foo() { final Object obj
Consider this scenario. I have an object, lets call it.... Foo. Foo raises a
Consider the following class hierarchy: base class Object with a virtual method foo() an
Consider example of the parser like this: object TestParser extends RegexParsers { override protected
Consider this multi-level nested JavaScript object. function foo() { var channels = { 2:
Consider the following: object Main { case class Foo(bar: Int) extends FooList { val
Consider this snippet: object A { val b = c val c = foo
Consider the following code: object foo { trait Bar[Q[_]] implicit object OptionBar extends Bar[Option]

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.