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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:34:19+00:00 2026-05-30T06:34:19+00:00

I have a class that essentially acts as a light weight wrapper class around

  • 0

I have a class that essentially acts as a light weight wrapper class around another class. It holds that other class as an iVar. I want to be able to expose certain properties (quite a few actually) of the iVar, but to do so I have to write out each property accessor like so:

- (void) setProperty:(Class *)value{
    _iVar.property = value;
}
- (Class *) property{
    return  _iVar.property;
}

Of course, I have to do this for every single property, which is a pain (there are about 30 of them). I would love to be able to synthesize this but I haven’t been able to figure out how.

Is it possible to synthesize?

Also, I can’t subclass….well, I might be able to but it’s really not recommended. The iVar class is really quite heavy (it implements CoreText). I’d rather write out the methods by hand.

  • 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-30T06:34:20+00:00Added an answer on May 30, 2026 at 6:34 am

    Ok, so here’s the solution I found…ended up being pretty simple once you knew what to do. First overwrite ‘- (id) forwardingTargetForSelector:(SEL)aSelector’ and return the iVar:

    - (id) forwardingTargetForSelector:(SEL)aSelector{
        return iVar;
    }
    

    When the runtime is looking for a method and cannot find one, it will call this method to see if there is another object to forward the message to. Note that this method normally returns nil and if you return nil here, your program will crash (which is the appropriate behavior).

    The second part of the problem is to shush the compiler errors/warnings you’ll get when you try to send a message that’s not declared. This is easily done by declaring a category you don’t implement.

    @interface Class (iVarClassMethods)
    @propoperty (strong) Class *property1;
    ......more properties
    @end
    

    As long as you don’t put in an implementation anywhere, aka @implementation Class (category), the compiler won’t complain (it’ll assume that the implementation is somewhere….).

    Now the only drawback I see is if you change any of the properties in the interface of the iVar Class, you need to make sure you update all other classes that use the method described above, otherwise you’ll crash when another class tries to send what is now the wrong method (and the compiler won’t warn you beforehand). However, this can be gotten around. You can declare protocols in a category. So instead you create a separate protocol for the iVar class and move the methods/properties you wish out of the iVar class into the protocol.

    @protocol iVarClassProtocol
    @propoperty (strong) Class *property1;
    ......more properties
    @end
    

    Add that protocol to the iVar subclass so it has those methods declared through the protocol now.

    @interface iVarClass <iVarClassProtocol>
    ....other methods/properties you don't need forwarded
    @end
    

    Finally, simply add the protocol to the category. So instead of the aforementioned category with explicit declarations you’ll have:

    @interface Class (iVarClassMethods) <iVarClassProtocol>
    @end
    

    Now, if you need to change any of the to-be-fowarded properties/methods, you change them in the protocol. The compiler will then warn you when you try to send the wrong method to the forwarding class.

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

Sidebar

Related Questions

I have a simple class that essentially just holds some values. I have overridden
I have a class that I want to use to store properties for another
I have a couple of functions inside a class that essentially do the same
I have a very large, spread out class that is essentially a very contrived
I have a class built with Moose that's essentially a data container for an
I have a button class that I wrote in CSS. It essentially displays block,
I have a generic class that essentially extends a linq class. This means that
Essentially I have a class that is used for safe invocation of delegates. Safe
I'm creating a base class Node that essentially wraps instances of another class from
I have a class that is essentially a message manager (a singleton) that has

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.